/*
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的更多相关文章

  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. Codeforces 449C Jzzhu and Apples 贪心 (看题解)

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

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

  4. Codeforces 449.C Jzzhu and Apples

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

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

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

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

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

  7. Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)

    题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...

  8. CF449C:Jzzhu and Apples

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

  9. Jzzhu and Apples CodeForces - 449C (构造,数学)

    大意: 求从[1,n]范围选择尽量多的数对, 使得每对数的gcd>1 考虑所有除2以外且不超过n/2的素数p, 若p倍数可以选择的有偶数个, 直接全部划分即可 有奇数个的话, 余下一个2*p不划 ...

随机推荐

  1. C# List数据批量更新

    针对单条数据一般都是update语句直接更新 例如:update UserTable set UserName='小名'   where userid=xxx 但是如果是针对List数据组进行更新的话 ...

  2. 复制DropDownList

    DropDownList ddlA; ListItem[] ar = new ListItem[ddlB.Items.Count]; ddlB.Items.CopyTo(ar,0); ddlA.Dat ...

  3. C++静态变量本身可否是一个实例对象

    一般书上总是用int来举例,那个太简单.如果静态变量本身可否是一个实例对象呢?应该是可以,但是这样涉及到它的构造函数以及它内部的静态变量如何初始化两个问题,换而言之,这个静态变量本身应该如何初始化?这 ...

  4. hdoj--2151--Worm(dp)

    Worm Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  5. 【转】iOS程序自动检测更新的实现 -- 思路不错

    原文网址:http://blog.csdn.net/davidsph/article/details/8931718 之前项目需要用到app自动更新的功能,现将实现方案分享出来.iOS程序自动提示更新 ...

  6. 智能识别收货地址 javascript

    欢迎加入前端交流群交流知识&&获取视频资料:749539640 地址: https://github.com/wzc570738205/smart_parse

  7. 学习笔记:javascript中的Generator函数

    最近在学习redux-saga,由于redux-saga需要使用Generator函数,所以下来就回顾了一下Generator Generator 函数是 ES6 提供的一种异步编程解决方案,语法行为 ...

  8. GStreamer基础教程01 - Hello World

    摘要 在面对一个新的软件库时,第一步通常实现一个“hello world”程序,来了解库的用法.对于GStreamer,我们可以实现一个极简的播放器,来了解GStreamer的使用. 环境配置 为了快 ...

  9. A - Translation

    Problem description The translation from the Berland language into the Birland language is not an ea ...

  10. 开发辅助 | 阿里图标库iconfont入门使用

    目前大多数的互联网公司,前端开发和UI设计师配合中,针对设计师给图的效果图,前端开发工程师不再像往常一样对于细小图标进行切图,取而代之的是引用阿里图标库(http://iconfont.cn/):简单 ...