日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Kate and imperfection CodeForces - 1333F(思维+数学)

發(fā)布時間:2023/12/15 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Kate and imperfection CodeForces - 1333F(思维+数学) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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個數(shù)字,每次任意挑選出k(2<=k<=n)個數(shù)字,任求k個數(shù)中兩個數(shù)的gcd,取最大值,求出所有k個數(shù)字組合中最大gcd值的最小值。把k所有的情況都求出來。
思路:貪心的去想,一開始加入的一定是素數(shù),因為素數(shù)的gcd一定是1
例如:n=10,這之中的素數(shù)有2,3,5,7。那么我們一開始加入這4個數(shù)字,在k=2,3,4的時候,gcd最大值最小化就是1.
但是當k=5的時候,就需要加入一個合數(shù)了,那么加入誰是最優(yōu)的呢?很明顯,是4。因為加入4,最終答案是2,這是最小的。
k=6的時候呢?這個時候應(yīng)該加入的是什么?此時如果加入6或者9,最終答案是3;如果加入8最終答案是4;如果加入10,最終答案是5;那么我們肯定加入的是6或者9。
很明顯了,加入一個合數(shù)之后,它的所帶來的的答案變化就是它的最大因子;素數(shù)就是1了。我們利用埃氏篩法的原理,貪心的處理出每一個數(shù)字的最大因子,然后排序之后輸出就可以了。
代碼如下:

#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;//因為素數(shù)永遠不可能被處理到,所以一開始就更新為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)/~

總結(jié)

以上是生活随笔為你收集整理的Kate and imperfection CodeForces - 1333F(思维+数学)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。