又是毕业季2

xiaoxiao2025-10-26  9

传送门

枚举答案,检查是当前数倍数的数的个数 还有一条性质,那就是,随着人数的递增,所得答案递减。 所以从上往下枚举答案即可。 代码如下:

#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n; int vis[1000005]; int ans[1000005]; int up; int check(int x){ if(ans[x]>0){ return ans[x]; } int y=x; while(y<=up){ ans[x]+=vis[y]; y+=x; } return ans[x]; } int main(){ int top=0; scanf("%d",&n); memset(vis,0,sizeof(vis)); for(int i=0;i<n;i++){ int x; scanf("%d",&x); vis[x]++; top=max(top,x); } up=top; memset(ans,0,sizeof(ans)); for(int i=1;i<=n;i++){ while(top>1&&check(top)<i){ top--; } printf("%d\n",top); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-5038530.html

最新回复(0)