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——题解的更多相关文章

  1. CF449C Jzzhu and Apples (筛素数 数论?

    Codeforces Round #257 (Div. 1) C Codeforces Round #257 (Div. 1) E CF450E C. Jzzhu and Apples time li ...

  2. CF449C Jzzhu and Apples

    嘟嘟嘟 这道题正解是怎么对的其实我也不清楚,总之靠感性理解吧. 首先当然要把1到n / 2的素数都筛出来,因为两两能配对的数一定都是这些素数的倍数.这也就说明对于(n / 2, n]的素数,他们一定不 ...

  3. Codeforces 449C Jzzhu and Apples 贪心 (看题解)

    Jzzhu and Apples 从大的质因子开始贪心, 如果有偶数个则直接组合, 如果是奇数个留下那个质数的两倍, 其余两两组合. #include<bits/stdc++.h> #de ...

  4. CF449 C. Jzzhu and Apples

    /* http://codeforces.com/problemset/problem/449/C cf 449 C. Jzzhu and Apples 数论+素数+贪心 */ #include &l ...

  5. 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 ...

  6. Codeforces 449.C Jzzhu and Apples

    C. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. CF 450E Jzzhu and Apples 数学+模拟

    E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces 450E:Jzzhu and Apples(构造,数学)

    E. Jzzhu and Apples time limit per test: 1 seconds memory limit per test: 256 megabytes input: stand ...

  9. CF449C:Jzzhu and Apples

    题意简述 给出正整数n,你要把1-n之间的正整数分成尽可能多组,使得每一组两个数的最大公约数大于1;输出能分成最多组的个数,并按任意顺序输出每组的两个数. 很妙的一道题. 首先我们考虑去处理每个质数的 ...

随机推荐

  1. MySQL日期、字符串、时间戳互转

    平时比较常用的时间.字符串.时间戳之间的互相转换,虽然常用但是几乎每次使用时候都喜欢去搜索一下用法:本文将作为一个笔记,整理一下三者之间的 转换(即:date转字符串.date转时间戳.字符串转dat ...

  2. 180605-Linux下Crontab实现定时任务

    Linux下Crontab实现定时任务 基于Hexo搭建的个人博客,是一种静态博客页面,每次新增博文或者修改,都需要重新的编译并发布到Github,这样操作就有点蛋疼了,一个想法就自然而然的来了,能不 ...

  3. HTMLTestRunner.py(Python3)

    """A TestRunner for use with the Python unit testing framework. Itgenerates a HTML re ...

  4. yarn logs -applicationId命令java版本简单实现

    import java.io.DataInputStream; import java.io.EOFException; import java.io.FileNotFoundException; i ...

  5. [Clr via C#读书笔记]Cp9参数

    Cp9参数 可选参数和命名参数 参数设置了默认值(设置要从右到左,有默认值的参数必须放在没有默认值的参数的后面,默认值必须是常量),就可以使用可选参数和命名参数了.向方法传递实参的时候,编译器按照从左 ...

  6. [转]bashrc与profile区别

    作者:KornLee 2005-02-03 15:49:57 来自:Linux先生 /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/pro ...

  7. docker 命令笔记

    docker images 查看镜像 docker search 查找镜像 docker pull 拉取镜像 docker push 推送镜像 docker ps 查看正在运行的容器 docker p ...

  8. metamask注记词

    leaf orbit poet zebra toy day put dinosaur review cool pluck throw(m) 一个钱包地址 里面有多个账号 菲苾代表了不同网络

  9. Jquery复选框

    Jquery复选框 1.checkbox list选择 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...

  10. location 匹配规则 (NGINX)

    转:https://moonbingbing.gitbooks.io/openresty-best-practices/ngx/nginx_local_pcre.html location 匹配规则 ...