luogu 1414

首先用个桶统计一下每个数出现多少次。

然后用类似埃氏筛法的方法统计每个数有多少个倍数,对于存在每一种倍数个数的数取一个max。

最后递推一下答案即可。

#include"cstdio"
#include"cctype"
#include"algorithm"
using namespace std;
int read()
{
    int c,x=0; while(!isdigit(c=getchar()));
    while(x=x*10+c-'0',isdigit(c=getchar()));
    return x;
}
int w[1000001],ans[10001];
int main()
{
    int n=read();
    for(int i=1; i<=n; i++) w[read()]++;
    for(int i=1; i<=1000000; i++)
    {
        for(int j=i*2; j<=1000000; j+=i) w[i]+=w[j];
        ans[w[i]]=i;
    }
    for(int i=n-1; i>=1; i--) ans[i]=max(ans[i+1],ans[i]);
    for(int i=1; i<=n; i++) printf("%d\n",ans[i]);
    return 0;
}

 

posted @ 2018-01-22 16:36  TrassBlose  阅读(81)  评论(0编辑  收藏  举报