CF449 C. Jzzhu and Apples
/*
http://codeforces.com/problemset/problem/449/C
cf 449 C. Jzzhu and Apples
数论+素数+贪心
*/
#include <cstdio>
#include <algorithm>
using namespace std;
const int Nmax=;
int is_prime[Nmax];
int book[Nmax];
int cnt[Nmax];
int n,ans;
void get__prime()
{
for(int i=;i<=n;i++)
is_prime[i]=;
for(int i=;i<=n;i++)
{
if(is_prime[i])
{
for(int j=;j*i<=n;j++)
{
is_prime[i*j]=;
}
}
}
} int main()
{
//freopen("cf449C.in","r",stdin);
scanf("%d",&n);
get__prime();
for(int i=n;i>=;i--)
{
if(is_prime[i])
{
cnt[i]=;
for(int j=;i*j<=n;j++)
{
if(!book[i*j])
{
cnt[i]++;
book[i*j]=;
}
}
if(cnt[i]&)
book[*i]=;
ans+=cnt[i]>>;
}
}
printf("%d\n",ans);
for(int i=;i<=n;i++)
book[i]=;
for(int i=n;i>=;i--)
{
if(is_prime[i] && cnt[i]>)
{
if(cnt[i]&)
{
int flag=;
for(int j=;i*j<=n;j++)
{
if(j==)
continue;
if(!book[i*j])
{
printf("%d",i*j);
if(flag)
printf(" ");
else
printf("\n");
flag^=;
book[i*j]=;
}
}
}
else
{
int flag=;
for(int j=;i*j<=n;j++)
{
if(!book[i*j])
{
printf("%d",i*j);
if(flag)
printf(" ");
else
printf("\n");
flag^=;
book[i*j]=;
}
}
}
}
}
return ;
}
CF449 C. 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 ...
- Codeforces 449C Jzzhu and Apples 贪心 (看题解)
Jzzhu and Apples 从大的质因子开始贪心, 如果有偶数个则直接组合, 如果是奇数个留下那个质数的两倍, 其余两两组合. #include<bits/stdc++.h> #de ...
- 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 ...
- Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)
题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...
- CF449C:Jzzhu and Apples
题意简述 给出正整数n,你要把1-n之间的正整数分成尽可能多组,使得每一组两个数的最大公约数大于1;输出能分成最多组的个数,并按任意顺序输出每组的两个数. 很妙的一道题. 首先我们考虑去处理每个质数的 ...
- Jzzhu and Apples CodeForces - 449C (构造,数学)
大意: 求从[1,n]范围选择尽量多的数对, 使得每对数的gcd>1 考虑所有除2以外且不超过n/2的素数p, 若p倍数可以选择的有偶数个, 直接全部划分即可 有奇数个的话, 余下一个2*p不划 ...
随机推荐
- DIV响应式
@media only screen and (min-width: 100px) and (max-width: 640px) { div { width: 100px; height: 100px ...
- luogu2508 [HAOI2008]圆上的整点
题目大意 给出\(r\),求圆\(x^2+y^2=r^2\)上坐标均为整数的点数.\(n<=2,000,000,000\) 总体思路 我们看到这个数据大小,还是个数学题,想到这个的时间复杂度应当 ...
- bzoj1081: [SCOI2005]超级格雷码(dfs)
1081: [SCOI2005]超级格雷码 题目:传送门 题解: 又是一道水题... 因为之前做过所以知道规律: 如n=2 B=3: 00 10 20 21 11 01 02 12 22 ...
- To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]
Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31 ...
- golang 初体验
1.下载golang https://code.google.com/p/go/downloads/list 在windows下安装,下载windows32版本 2.安装 安装完毕,默认在C:\Go ...
- Comparable与Comparator源码分析
package java.lang; import java.util.*; /** * This interface imposes a total ordering on the objects ...
- [luogu P5349] 幂 解题报告 (分治FFT)
interlinkage: https://www.luogu.org/problemnew/show/P5349 description: solution: 设$g(x)=\sum_{n=0}^{ ...
- Fail2ban + firewalld 防护doss攻击
系统环境:centos7.3 用途:利用fail2ban+Firewalld来防CC攻击和SSH爆破 准备工作: 1.检查Firewalld是否启用 #如果您已经安装iptables建议先关闭 ser ...
- Docker的官网在线--中文教程
1.官网界面:https://www.docker.com/tryit/ In this 10-minute tutorial, see how Docker works first-hand: Yo ...
- 几个方便编程的C++特性
前言: C++11的自动化特性给编程提供了不少方便,同时也给调试增加了很多负担,至于取舍看程序员的风格和侧重而定. auto:自动类型推断 在C++11之前,auto关键字用来指定存储期.在新标准中, ...