题目: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; }
原文地址:https://www.cnblogs.com/Narh/p/9887162.html
时间: 2024-10-06 02:39:28