bzoj 1607 [Usaco2008 Dec]Patting Heads 轻拍牛头——枚举倍数
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1607
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=1e5+5,M=1e6+5; int n,a[N],c[M],mx,ans[M]; int rdn() { int ret=0;bool fx=1;char ch=getchar(); while(ch>'9'||ch<'0'){if(ch=='-')fx=0;ch=getchar();} while(ch>='0'&&ch<='9') ret=(ret<<3)+(ret<<1)+ch-'0',ch=getchar(); return fx?ret:-ret; } int g[20]; void wrt(int x) { if(x<0)putchar('-'),x=-x; if(!x){puts("0");return;} int t=0;while(x)g[++t]=x%10,x/=10; while(t)putchar(g[t]+'0'),t--;puts(""); } int main() { n=rdn();for(int i=1;i<=n;i++)a[i]=rdn(),c[a[i]]++,mx=max(mx,a[i]); for(int i=1;i<=mx;i++) if(c[i]) for(int j=i;j<=mx;j+=i)ans[j]+=c[i]; for(int i=1;i<=n;i++)wrt(ans[a[i]]-1); return 0; }