bzoj 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
翻过来考虑影响,考虑多少数是他的倍数。
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdlib> 5 #include<cmath> 6 #include<queue> 7 #include<algorithm> 8 #include<vector> 9 #define M 1000009 10 #define EPS 1e-10 11 #define ll long long 12 using namespace std; 13 ll read() 14 { 15 char ch=getchar(); 16 ll x=0,f=1; 17 for(;ch<'0'||ch>'9';ch=getchar()) 18 if(ch=='-') 19 f=-1; 20 for(;ch>='0'&&ch<='9';ch=getchar()) 21 x=x*10+ch-'0'; 22 return x*f; 23 } 24 int n,sum[M],a[M],b[M],T,mx; 25 int main() 26 { 27 n=read(); 28 for(int i=1;i<=n;i++) 29 { 30 a[i]=read(); 31 b[a[i]]++; 32 mx=max(mx,a[i]); 33 } 34 for(int i=1;i<=mx;i++) 35 if(b[i]) 36 { 37 for(int j=i;j<=mx;j+=i) 38 sum[j]+=b[i]; 39 } 40 for(int i=1;i<=n;i++) 41 printf("%d\n",sum[a[i]]-1); 42 return 0; 43 }