Kate and imperfection CodeForces - 1333F(思维+数学)
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了。我們利用埃氏篩法的原理,貪心的處理出每一個數字的最大因子,然后排序之后輸出就可以了。
代碼如下:
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的Kate and imperfection CodeForces - 1333F(思维+数学)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我国银行排名,中国各大银行排行榜
- 下一篇: Bound Found POJ - 25