luogu 1414 又是毕业季II 约数相关
感觉好水呀~
Code:
#include <cstdio> #include <algorithm> #define N 1000005 #define setIO(s) freopen(s".in","r",stdin) using namespace std; int sum[N],vis[N],Mx[N],val[N]; int main() { int i,j,n; // setIO("input"); scanf("%d",&n); for(i=1;i<=n;++i) scanf("%d",&val[i]),++vis[val[i]]; for(i=1;i<N;++i) for(j=i;j<N;j+=i) sum[i]+=vis[j]; for(i=1;i<N;++i) Mx[sum[i]]=max(Mx[sum[i]],i); for(i=n-1;i>=1;--i) Mx[i]=max(Mx[i],Mx[i+1]); for(i=1;i<=n;++i) { printf("%d\n",Mx[i]); } return 0; }