/*
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. springboot集成grpc

    gRPC 简介 gRPC 是一个现代开源的高性能 RPC 框架,可以在任何环境下运行.它可以有效地将数据中心内和跨数据中心的服务与可插拔支持进行负载均衡.跟踪.健康检查和认证.它也适用于分布式计算,将 ...

  2. 【JNI探索之路系列】之七:JNI要点总结

    作者:郭嘉 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells github:https://github.com/AllenWells ...

  3. php中一个经典的!==的用法

    php中一个经典的!==的用法 <?php $str = 'Every time you bleed for reaching greatness.'; $cha = 'E'; if(strpo ...

  4. [BZOJ 2100] Apple Delivery

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2100 [算法] Answer = min{ dist(PB,PA1) + dist( ...

  5. 【优化算法】遗传算法GA求解混合流水车间调度问题(附C++代码)

    00 前言 各位读者大家好,好久没有介绍算法的推文了,感觉愧对了读者们热爱学习的心灵.于是,今天我们带来了一个神奇的优化算法--遗传算法! 它的优点包括但不限于: 遗传算法对所求解的优化问题没有太多的 ...

  6. MarkDownPad 注册码

    邮箱: Soar360@live.com 授权秘钥: GBPduHjWfJU1mZqcPM3BikjYKF6xKhlKIys3i1MU2eJHqWGImDHzWdD6xhMNLGVpbP2M5SN6b ...

  7. css要点

    1.对inline-block设置overflow: hidden会造成baseline移动,因此需要设置vertical-align才不会出现样式问题. 2.使用flex时,需要对设置flex: 1 ...

  8. Android ToolBar自定义图标,关联DrawerLayout

    Android5.0出现了一个可以代替ActionBar的控件ToolBar,使用更加灵活,一般我们使用ToolBar来和DrawerLayout配合使用,官方提供了一个开关类ActionBarDra ...

  9. android 自定义空间 组合控件中 TextView 不支持drawableLeft属性

    android 自定义空间 组合控件中 TextView 不支持drawableLeft属性.会报错Caused by: android.view.InflateException: Binary X ...

  10. 关于VS 2013连接Microsoft Access 2013的相关问题

      ①   下载安装Microsoft Access Database Engine 2010 Redistributable(28MB),共有32bit(下载)和64bit(下载)两个版本,具体要安 ...