http://www.lydsy.com/JudgeOnline/problem.php?id=1607
应该算是中档水题
思想的话基本上就是筛选法
只不过这次的筛选法有所不同
不是去筛质数
而是根据给定的数来筛选
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline void read(int &x){char ch;bool ok;
for(ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') ok=1;
for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok) x=-x;}
const int N=1e6;
int A[N],B[N],C[N];
int main(){
int n;
int x;
read(n);
for(int i=1;i<=n;++i){
read(x);
A[i]=x;
B[x]++;
}
for(int i=1;i<=N;++i){
if(B[i]==0)
continue;
C[i]+=B[i]-1;
for(int j=i*2;j<=N;j+=i)
C[j]+=B[i];
}
for(int i=1;i<=n;++i)
printf("%d\n",C[A[i]]);
}