链接:https://codeforc.es/contest/1333/problem/F
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
input
Copy
2
output
Copy
1
input
Copy
3
output
Copy
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>
using namespace std;
long long n,t,l,k,s,sum;
long long a[500001],b[200001];
map<long long,long long>m;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
a[i]=1;
for(int i=2;i<=n;i++)
{
if(a[i]==1)
{
for(int j=i*2;j<=n;j+=i)
{
if(a[j]==1)
a[j]=j/i;
}
}
}
sort(a+1,a+1+n);
for(int i=2;i<=n;i++)
{
cout<<a[i]<<' ';
}
}