1 /*
 2 http://codeforces.com/problemset/problem/449/C
 3 cf 449 C. Jzzhu and Apples
 4 数论+素数+贪心
 5 */
 6 #include <cstdio>
 7 #include <algorithm>
 8 using namespace std;
 9 const int Nmax=100005;
10 int is_prime[Nmax];
11 int book[Nmax];
12 int cnt[Nmax];
13 int n,ans;
14 void get__prime()
15 {
16     for(int i=2;i<=n;i++)
17         is_prime[i]=1;
18     for(int i=2;i<=n;i++)
19     {
20         if(is_prime[i])
21         {
22             for(int j=2;j*i<=n;j++)
23             {
24                 is_prime[i*j]=0;
25             }
26         }
27     }
28 }
29
30 int main()
31 {
32     //freopen("cf449C.in","r",stdin);
33     scanf("%d",&n);
34     get__prime();
35     for(int i=n;i>=2;i--)
36     {
37         if(is_prime[i])
38         {
39             cnt[i]=1;
40             for(int j=2;i*j<=n;j++)
41             {
42                 if(!book[i*j])
43                 {
44                     cnt[i]++;
45                     book[i*j]=1;
46                 }
47             }
48             if(cnt[i]&1)
49                 book[2*i]=0;
50             ans+=cnt[i]>>1;
51         }
52     }
53     printf("%d\n",ans);
54     for(int i=1;i<=n;i++)
55         book[i]=0;
56     for(int i=n;i>=2;i--)
57     {
58         if(is_prime[i] && cnt[i]>1)
59         {
60             if(cnt[i]&1)
61             {
62                 int flag=1;
63                 for(int j=1;i*j<=n;j++)
64                 {
65                     if(j==2)
66                         continue;
67                     if(!book[i*j])
68                     {
69                         printf("%d",i*j);
70                         if(flag)
71                             printf(" ");
72                         else
73                             printf("\n");
74                         flag^=1;
75                         book[i*j]=1;
76                     }
77                 }
78             }
79             else
80             {
81                 int flag=1;
82                 for(int j=1;i*j<=n;j++)
83                 {
84                     if(!book[i*j])
85                     {
86                         printf("%d",i*j);
87                         if(flag)
88                             printf(" ");
89                         else
90                             printf("\n");
91                         flag^=1;
92                         book[i*j]=1;
93                     }
94                 }
95             }
96         }
97     }
98     return 0;
99 }

转载于:https://www.cnblogs.com/BBBob/p/6611033.html

CF449 C. Jzzhu and Apples相关推荐

  1. php根据指定字段去重,php二维数组根据某个字段去重

    php的二维数组根据某个字段去重,在这默认为二维数组的结构是一样的,现在根据二维数组里的id字段去重,把id相同的重复的元素去掉 /** * 二维数组根据某个字段去重 * @param array $ ...

  2. CodeForces:749(div1)750(div2)

    文章目录 前言 CF450A Jzzhu and Children Description\text{Description}Description Solution\text{Solution}So ...

  3. czl蒻蒟的OI之路10、11、12

    好久没有发微博了表示自己也很绝望啊今天来个三连击 XJOI奋斗群蒻蒟群群赛11 RANK排名11 T1The Wall WA一次后AC 题意 分析过程 给出题解 T2Maximal Area Quad ...

  4. CF刷题——2500难度的几道题

    1.D. Beautiful numbers 题意:Beautiful Numbers定义为这个数能整除它的所有位上非零整数.问[l,r]之间的Beautiful Numbers的个数. 数位 DP: ...

  5. CF449B Jzzhu and Cities 迪杰斯特拉最短路算法

    CF449B Jzzhu and Cities 其实这一道题并不是很难,只是一个最短路而已,请继续看我的题解吧~(^▽^) AC代码: #include<bits/stdc++.h> #d ...

  6. Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences

    B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. Educational Codeforces Round 9 A. Grandma Laura and Apples 水题

    A. Grandma Laura and Apples 题目连接: http://www.codeforces.com/contest/632/problem/A Description Grandm ...

  8. Codeforces Round #257 (Div. 1) D. Jzzhu and Numbers 高维前缀和 + 容斥

    传送门 文章目录 题意: 思路: 题意: 思路: 完全想不到容斥啊,看了半天也没看懂渍渍渍. 定义f[i]f[i]f[i]表示iii的超集个数,那么选择的方案就是2f[i]−12^{f[i]}-12f ...

  9. [数据结构专训][GXOI/GZOI2019]旧词,[hdu5118]GRE Words Once More!,[hdu6333]Problem B. Harvest of Apples

    文章目录 T1:[GXOI/GZOI2019]旧词 solution code T2:GRE Words Once More! solution code T3:Problem B. Harvest ...

最新文章

  1. 基数排序中的LSD方法和MSD方法
  2. 第六届福建省大学生程序设计竞赛(FZU2213—FZU2221)
  3. 热更新--动态加载framework
  4. vue-cli 官方模板webpack-simple的npm run dev 与npm run bulid的一些问题
  5. WP8.1 Study18:动态磁贴
  6. 关于python中多态的理解。
  7. php 数组导出csv_php导出CSV抽象类实例
  8. [以太坊源代码分析]III. 挖矿和共识算法的奥秘
  9. L2正则没有想象那么好?可能是“权重尺度偏移”惹的祸
  10. 中秋水文 | 安利一发国漫
  11. jvm jstat_使用jstat报告自定义JVM指标集
  12. 高级ZK:异步UI更新和后台处理–第2部分
  13. uva 11728——Alternate Task
  14. shiro学习(20): 自定义过滤规则
  15. 错误Unable to find manifest signing certificate in the certificat...
  16. Markdown Pad2--公式编辑功能搭建
  17. 树莓派与Arduino Leonardo使用NRF24L01无线模块通信之基于RF24库 (四) 树莓派单子节点查询...
  18. sql server 排名函数:DENSE_RANK
  19. 微信公众号卡券php开发,微信公众号实现会员卡领取功能
  20. R语言中dim函数_R语言在医学统计中的应用基础教程

热门文章

  1. 青岛西海岸惠普大数据_青岛西海岸新区用好卫星大数据 为城市治理全面赋能...
  2. 流浪宠物救助网站前端页面_全国爱心人士齐聚鞍山 救助流浪猫狗
  3. 计算机系统组成图表,Excel2013中的图表作用组成类型与认识(上)——想象力电脑应用...
  4. SQLServer数据库实例相关知识笔记
  5. 硬件:如何选购适合自己的显示器
  6. python滚动文本框_调整滚动Tkinter文本框的大小
  7. 基本系统设备感叹号_win7系统网络图标显示感叹号的问题
  8. python json dumps utf8_Python2操作JSON出现乱码的解决方案
  9. python如何确定拐点_多年股市老鸟买卖操作经验——如何在波段操作确定买入点!经典...
  10. 数据库 CURD测试题【简单】