Kate and imperfection CodeForces - 1333FEratosthenes筛
作者:互联网
Kate has a set SS of nn integers {1,…,n}{1,…,n}.
She thinks that imperfection of a subset M⊆SM⊆S is equal to the maximum of gcd(a,b)gcd(a,b) over all pairs (a,b)(a,b) such that both aa and bb are in MM and a≠ba≠b.
Kate is a very neat girl and for each k∈{2,…,n}k∈{2,…,n} she wants to find a subset that has the smallest imperfection among all subsets in SS of size kk. 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 kk, will name it IkIk.
Please, help Kate to find I2I2, I3I3, ..., InIn.
Input
The first and only line in the input consists of only one integer nn (2≤n≤5⋅1052≤n≤5⋅105) — the size of the given set SS.
Output
Output contains only one line that includes n−1n−1 integers: I2I2, I3I3, ..., InIn.
Examples
Input2Output
1Input
3Output
1 1
Note
First sample: answer is 1, because gcd(1,2)=1gcd(1,2)=1.
Second sample: there are subsets of SS with sizes 2,32,3 with imperfection equal to 1. For example, {2,3}{2,3} and {1,2,3}{1,2,3}.
#include <bits/stdc++.h> #include <iostream> #include <cstdio> #include <cmath> #include<cstring> #include <algorithm> #include <queue> #include<map> #include<set> #include<vector> using namespace std; typedef long long ll; const int inf = 1e9; const int mod = 1000000007; const int mx = 5e5+10; //check the limits, dummy typedef pair<int, int> pa; const double PI = acos(-1); ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } #define swa(a,b) a^=b^=a^=b #define re(i,a,b) for(int i=(a),_=(b);i<_;i++) #define rb(i,a,b) for(int i=(a),_=(b);i>=_;i--) #define clr(a) memset(a, -1, sizeof(a)) #define lowbit(x) ((x)&(x-1)) #define mkp make_pai void sc(int& x) { scanf("%d", &x); }void sc(int64_t& x) { scanf("%lld", &x); }void sc(double& x) { scanf("%lf", &x); }void sc(char& x) { scanf(" %c", &x); }void sc(char* x) { scanf("%s", x); } int n, m, k,ans=0,t,p,x; int a[mx]; vector<int>maxdiv; void fuck(int limit) { maxdiv.assign(limit + 1, 0); maxdiv[0] = limit + 10; maxdiv[1] = 1; re(i, 2, limit + 1) { if (maxdiv[i])continue; for (int j = i; j <=limit; j+=i) { if (maxdiv[j])continue; maxdiv[j] = j / i; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; fuck(n); sort(maxdiv.begin(), maxdiv.end()); re(i, 1, n)cout << maxdiv[i] << ' '; return 0; }
标签:maxdiv,1333FEratosthenes,void,imperfection,CodeForces,int,include,Kate,define 来源: https://www.cnblogs.com/xxxsans/p/12771694.html