- 对n个数,我们考虑它对整个gcd集合的贡献,对于质数,它只能贡献1,对于合数,它所有的因子都在集合中(gcd(A,A的因子)= A的因子)。要输出选i个数中的最小的gcd最大值。那就把前i个数的的贡献从小到大排序,输出。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
#include<string>
#include<fstream>
using namespace std;
typedef long long ll;
const int N = 5e5 + 105;
const int mod = 998244353;
const double Pi = acos(- 1.0);
const int INF = 0x3f3f3f3f;
const int G = 3, Gi = 332748118;
int vis[N * 2];
int res[N * 2];
void prime(){
vis[1] = 1;
vis[2] = 0;
for(int i = 2; i < N; ++ i){
if(!vis[i]){
res[i] = 1;
for(int j = i + i; j < N; j += i){
vis[j] = 1;
res[j] = max(res[j], j / i);
}
}
}
}
//
int n;
int main()
{
prime();
res[1] = 1;
scanf("%d",&n);
sort(res + 1, res + n + 1);
for(int i = 2; i <= n; ++ i){
if(i == n) printf("%d
", res[i]);
else printf("%d ",res[i]);
}
return 0;
}