标签:|| stream dso www clu rap problem col algo
http://www.bnuoj.com/problem_show.php?pid=1026&tdsourcetag=s_pcqq_aiomsg
5 2 1 2 3 4
2 0 2 1 3
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <cmath> using namespace std; int read() { int sum=0,fg=1; char c=getchar(); while(c<‘0‘||c>‘9‘){ if(c==‘-‘)fg=-1;c=getchar(); } while(c>=‘0‘&&c<=‘9‘){ sum=sum*10+c-‘0‘;c=getchar(); } return sum*fg; } int n,ans,a[100006],sum[1000006],vis[1000006]; int main() { // freopen("A.in","r",stdin); // freopen("A.out","w",stdout); n=read(); for(int i=1;i<=n;i++)a[i]=read(),sum[a[i]]++; for(int i=1;i<=n;i++) { if(vis[a[i]]>0) { printf("%d\n",vis[a[i]]); continue; } ans=0; int p=sqrt(a[i]); for(int j=1;j<=p;j++) { if(a[i]%j==0) { if(a[i]/j==j)ans+=sum[j]; else ans+=sum[j],ans+=sum[a[i]/j]; } } vis[a[i]]=ans-1; printf("%d\n",ans-1); } // fclose(stdin);fclose(stdout); }
标签:|| stream dso www clu rap problem col algo
原文地址:https://www.cnblogs.com/rmy020718/p/9610380.html