Kate and imperfection

Link: Kate and imperfection

Description

Kate has a set S of n integers .

She thinks that imperfection of a subset is equal to the maximum of over all pairs such that both a and b are in M and .

Kate is a very neat girl and for each 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 .

Please, help Kate to find , , ..., .

Input
The first and only line in the input consists of only one integer n () — the size of the given set S.

Output
Output contains only one line that includes n−1 integers: , , ..., .

Examples

input
2
output
1
input
3
output
1 1

Note
First sample: answer is 1, because .

Second sample: there are subsets of S with sizes 2,3 with imperfection equal to 1. For example, and .

Problem solving

这道题的意思就是给你一个数n,让你分别找出这个序列的长度为的子序列,使得子序列中两两间的的最大值最小。输出这个最小值。

如果有质数,我们一定是往里面放质数。当质数用完的时候,我们怎么办呢?
因为我们要求的是两两间的的最大值的最小。所以我们可以先放与当前序列中质数的为2的数,然后是3,直到放完
放完之后,放入的每一个数的每一个因子在序列中都存在了,所以此时能产生的最大的就是它的最大的因子。

然后我们用一个数组维护某一个数的最大因子,然后排序输出即可。

Code

#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+10;
int p[maxn];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)   p[i]=1;
    for(int i=2;i<=n;i++){
        for(int j=i+i;j<=n;j+=i){
            p[j]=i;
        }
    }
    sort(p+1,p+1+n);
    for(int i=2;i<=n;i++)   cout<<p[i]<<" ";
    return 0;
}