CF449C:Jzzhu and Apples——题解
https://vjudge.net/problem/CodeForces-449C
题目大意:1-n编号的苹果两两一对,他们的最大公约数不为1,求这些对的最大匹配。
————————————————————————————————
我们显然先把素数筛出来。
然后我们从后往前循环素数p,然后p,2p,3p(取过的自动不要)……这些数两两都可以成一对。
但是如果是奇数个,我们就抛掉2p,因为2p一定可以与其他2的倍数一对。
不知道怎么证明……
#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>
https://vjudge.net/problem/CodeForces-449Cusing namespace std;
typedef long long ll;
const int N=1e5+;
int su[N];
bool he[N];
void Eratosthenes(int n){
for(int i=;i<=n;i++){
if(he[i]!=)continue;
for(int j=;j*i<=n;j++)he[j*i]=;
}
return;
}
vector<int>a;
int p[N][];
bool ok[N];
int main(){
int n;
scanf("%d",&n);
Eratosthenes(n);
int ans=;
for(int i=n/;i>=;i--){
if(he[i])continue;
a.clear();
for(int j=i;j<=n;j+=i){
if(!ok[j]){
a.push_back(j);
}
}
if(a.size()%)swap(a[],a[a.size()-]);
for(int j=;j<a.size()-;j+=){
ans++;
p[ans][]=a[j];ok[a[j]]=;
p[ans][]=a[j+];ok[a[j+]]=;
}
}
printf("%d\n",ans);
for(int i=;i<=ans;i++){
printf("%d %d\n",p[i][],p[i][]);
}
return ;
}
CF449C:Jzzhu and Apples——题解的更多相关文章
- CF449C Jzzhu and Apples (筛素数 数论?
Codeforces Round #257 (Div. 1) C Codeforces Round #257 (Div. 1) E CF450E C. Jzzhu and Apples time li ...
- CF449C Jzzhu and Apples
嘟嘟嘟 这道题正解是怎么对的其实我也不清楚,总之靠感性理解吧. 首先当然要把1到n / 2的素数都筛出来,因为两两能配对的数一定都是这些素数的倍数.这也就说明对于(n / 2, n]的素数,他们一定不 ...
- Codeforces 449C Jzzhu and Apples 贪心 (看题解)
Jzzhu and Apples 从大的质因子开始贪心, 如果有偶数个则直接组合, 如果是奇数个留下那个质数的两倍, 其余两两组合. #include<bits/stdc++.h> #de ...
- CF449 C. Jzzhu and Apples
/* http://codeforces.com/problemset/problem/449/C cf 449 C. Jzzhu and Apples 数论+素数+贪心 */ #include &l ...
- Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟
E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 449.C Jzzhu and Apples
C. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CF 450E Jzzhu and Apples 数学+模拟
E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 450E:Jzzhu and Apples(构造,数学)
E. Jzzhu and Apples time limit per test: 1 seconds memory limit per test: 256 megabytes input: stand ...
- CF449C:Jzzhu and Apples
题意简述 给出正整数n,你要把1-n之间的正整数分成尽可能多组,使得每一组两个数的最大公约数大于1;输出能分成最多组的个数,并按任意顺序输出每组的两个数. 很妙的一道题. 首先我们考虑去处理每个质数的 ...
随机推荐
- possible new indexes 出现了
- ASP.NET数据库连接
启动Visual Studio,新建一个web工程 点开工程目录下web.config文件, 找到节点,新增数据库配置 aspx界面新建一个button和一个文本框用于测试数据库连接, 其中butto ...
- UnityShader - 模拟动态光照特效
模型贴片 + 特效Shader = 动态光照特效 效果是这样的: 做法简单粗暴,直接使用模型贴片: shader上使用了noise只是提供一种思路,也有更简单的方法代替
- vim python自动补全插件:pydiction
vim python自动补全插件:pydiction 可以实现下面python代码的自动补全: 1.简单python关键词补全 2.python 函数补全带括号 3.python 模块补全 4.pyt ...
- leetcode-二叉树的层次遍历(Java)
给定一个二叉树,返回其按层次遍历的节点值. (即逐层地,从左到右访问所有节点). 例如:给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回其层 ...
- 标注点(Labeled Point)
标注点LabeledPoint是一种带有标签(Label/Response)的本地向量,它可以是稠密或者是稀疏的.在MLlib中,标注点在监督学习算法中被使用.由于标签是用双精度浮点型来存储的,故标注 ...
- Linux的基础预备知识
Linux下一切皆文件 1.root@mk-virtual-machine:/home/mk# root:该位置表示当前终端登录的用户名 mk-virtual-machine:/home/m ...
- 详解Jedis连接池报错处理
在使用Jedis连接池模式下,比较常见的报错如下: redis.clients.jedis.exceptions.JedisConnectionException:Could not get a re ...
- Ubuntu—安装并运行sublime
step1 到官网看看 https://www.sublimetext.com/3 step2 根据版本选择,我的是32位的 step3 ubuntu终端安装 (1)切换目录 -$ cd /opt ...
- windows store无法登陆的问题解决方案
Windows应用商店或商店Apps无法打开或闪退的可选方法 (仅用于10565之前的Windows 10版本) 右键点击任务栏,选择"属性",切换到"导航"选 ...