Kate has a set S of n integers {1,…,n}.

She thinks that imperfection of a subset M⊆S is equal to the maximum of gcd(a,b) over all pairs (a,b) such that both a and b are in M and a≠b.

Kate is a very neat girl and for each k∈{2,…,n} she wants to find a subset that has the smallest imperfection among all subsets in S of size k. There can be more than one subset with the smallest imperfection and the same size, but you don’t need to worry about it. Kate wants to find all the subsets herself, but she needs your help to find the smallest possible imperfection for each size k, will name it Ik.

Please, help Kate to find I2, I3, …, In.

Input
The first and only line in the input consists of only one integer n (2≤n≤5⋅105) — the size of the given set S.

Output
Output contains only one line that includes n−1 integers: I2, I3, …, In.

Examples
Input
2
Output
1
Input
3
Output
1 1
Note
First sample: answer is 1, because gcd(1,2)=1.

Second sample: there are subsets of S with sizes 2,3 with imperfection equal to 1. For example, {2,3} and {1,2,3}.
题意:给你1~n一共n个数字,每次任意挑选出k(2<=k<=n)个数字,任求k个数中两个数的gcd,取最大值,求出所有k个数字组合中最大gcd值的最小值。把k所有的情况都求出来。
思路:贪心的去想,一开始加入的一定是素数,因为素数的gcd一定是1
例如:n=10,这之中的素数有2,3,5,7。那么我们一开始加入这4个数字,在k=2,3,4的时候,gcd最大值最小化就是1.
但是当k=5的时候,就需要加入一个合数了,那么加入谁是最优的呢?很明显,是4。因为加入4,最终答案是2,这是最小的。
k=6的时候呢?这个时候应该加入的是什么?此时如果加入6或者9,最终答案是3;如果加入8最终答案是4;如果加入10,最终答案是5;那么我们肯定加入的是6或者9。
很明显了,加入一个合数之后,它的所带来的的答案变化就是它的最大因子;素数就是1了。我们利用埃氏筛法的原理,贪心的处理出每一个数字的最大因子,然后排序之后输出就可以了。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;const int maxx=5e5+100;
int a[maxx];
int vis[maxx];
int n;int main()
{scanf("%d",&n);int cnt=0;for(int i=1;i<=n+1;i++) a[i]=1;//因为素数永远不可能被处理到,所以一开始就更新为1.for(int i=2;i<=n;i++){for(int j=i+i;j<=n;j+=i) a[j]=i;//不断的更新最大值。}sort(a+1,a+1+n);for(int i=2;i<=n;i++) cout<<a[i]<<" ";return 0;
}

努力加油a啊,(o)/~

Kate and imperfection CodeForces - 1333F(思维+数学)相关推荐

  1. Codeforces Round #632 (Div. 2) F. Kate and imperfection 数论 + 贪心

    传送门 文章目录 题意: 思路: 题意: n≤5e5n\le5e5n≤5e5 思路: 首先有个显然的结论:当往集合中加入一个数xxx的时候,如果存在d∣xd|xd∣x且ddd不在集合中,那么加入ddd ...

  2. c语言小红今年12岁小明13岁,[转载]三年级下“创新思维数学讲义”——年龄问题...

    三年级下"创新思维数学讲义"-- 年龄问题 邵 玲 热身场 相传,乾隆皇帝下江南时,遇到了一位老寿星.老人鹤发童颜,精神焕发,乾隆皇帝当即赠一上联给老人,写的是:"花甲重 ...

  3. nowcoder_A_放羊的贝贝_思维+数学

    nowcoder_A_放羊的贝贝_思维+数学 放羊的贝贝​​​​​​​ 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO For ...

  4. CodeForces - 1333F Kate and imperfection(数论+贪心)

    题目链接:点击查看 题目大意:初始时有一个 1 ~ n 共 n 个元素的集合,现在需要选出恰好有 k 个元素的一个子集,使得子集中两两元素进行 gcd 运算后的最大值最小,分别输出 k ∈[ 2 , ...

  5. CodeForces - 364A Matrix(思维+数学)

    题目链接:点击查看 题目大意:给出一个长度为 n 的,只由十进制数字组成的字符串 s,可以构造出一个大小为 n * n 的矩阵,构造方法如下:b[ i ][ j ] = s[ i ] * s[ j ] ...

  6. Codeforces Round #410 (Div. 2) D. Mike and distribution 思维+数学

    链接: http://codeforces.com/contest/798/problem/D 题意: 给你两个长度为n的数列a和b,让你选n/2+1个下标,使得2*∑ai>suma,2*∑bi ...

  7. CodeForces - 1213A Chips Moving (思维 数学)

    CodeForces - 1213A Chips Moving 题目: You are given n chips on a number line. The i-th chip is placed ...

  8. CodeForces - 1323D Present(思维+数学)

    题目链接:点击查看 题目大意:给出一个数列 a ,求出 题目分析:如果暴力的话显然时间复杂度是 n * n 的,我们应该想办法去优化,比赛的时候想用线段树,但是不会在维护异或的前提下区间加法,也想过用 ...

  9. CodeForces - 1469D - Ceil Divisions (思维+数学)

    Ceil Divisions 题意 对于一个大小为 n n n 的排列 在一次操作中可以选择两个数 a x a_x ax​ 和 a y a_y ay​ ( x ≠ y ) (x≠y) (x​=y) ...

最新文章

  1. Ether-channel 以太网通道
  2. 技术图文:进一步完善自动化交易系统 - 01
  3. 黄聪:SQL server 2005高可用性之----数据库镜像
  4. jQuery 序列化表单数据 serialize() serializeArray()
  5. MATLAB实战系列(二十四)-大规模邻域搜索(LNS)求解带时间窗的车辆路径问题(VRPTW)(附matlab源代码)
  6. python integer_【Python】string/list/integer常用函数总结
  7. 人工智障学习笔记——强化学习(4)时间差分方法
  8. access control java_Java Access Controller
  9. python的panda是什么库_Python的Pandas库简述
  10. c/c++ 中文件路径的表示
  11. 安装Go 1.9.2
  12. zabbix登陆拒绝报没有权限
  13. VsCode开发Flutter 连接夜神模拟器
  14. spring boot内置容器性能比较(Jetty、Tomcat、Undertow)
  15. 谷歌搜索引擎总是被修改
  16. android 二级联动列表,仿eleme点餐页面
  17. 嵌入式linux机械臂,一款基于ARM嵌入式的机械臂的设计与实现
  18. 线上问题处理1---CPU飙高问题定位
  19. 手把手教你React Native接入聊天IM即时通讯功能-源码分享
  20. 暂存分支 Git stash

热门文章

  1. 如何将计算机专业知识和水文结合,2016水文勘测理论知识及参考答案 B卷
  2. spring 点击保存按钮页面禁用_用一篇深度好文,详解按钮的设计
  3. python selenium_Python+selenium自动化测试
  4. 如何在vue中使用图形验证码
  5. java 字节码对象_获得类的字节码对象的三种方式
  6. Android WebView与JavaScript交互详解
  7. Android开发之非常好用的日志工具类(公司项目挖出来的)
  8. Android中软键盘(输入法)收起的方法
  9. Android开发编码规范pdf文件下载
  10. PHP考试插件,php秒杀插件?