The main question: in the number of N, for each of the number, in the other (n-1) the number of several is his factor.
The puzzle: Considering that the range of the AI is not too large, you can use a bucket to count the number of 1~max (AI), and then sift the 1~max in multiples of MAX. 100,000 numbers in 1000000 barrels are very sparse, ignoring the number of occurrences of 0 is very important for time efficiency.
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <cctype>5#include <iostream>6 using namespacestd;7 #defineMaxx 10000078 #defineMAXN 2333339 #definell Long LongTen inta[maxn],num[maxx],n,max=0; One ll F[maxx]; A intQread () - { - CharCints=0, t=1; the while(!isdigit (C=getchar ()))if(c=='-') t=-1; - Do{s=s*Ten+c-'0';} while(IsDigit (c=GetChar ())); - returns*T; - } + intMain () - { +n=Qread (); Amemset (NUM,0,sizeof(num)); at for(intI=1; i<=n;i++) A[i]=qread (), num[a[i]]++,max=Max (A[i],max); - for(intI=1; i<=max;i++) - if(Num[i]) for(intJ=i;j<=max;j+=i) f[j]+=Num[i]; - for(intI=1; i<=n;i++) printf ("%lld\n", f[a[i]]-1); - return 0; -}
View Code
1607 [Usaco2008 dec]patting Heads Pat Bull Head