10
15
2015
0

[BZOJ1607] [Usaco2008 Dec] Patting Heads 轻拍牛头

这是一个筛法。

#include<cstdio>
#include<algorithm>
using namespace std;

int n,a[1000005],s[1000005],c[1000005],mx;

int main(){
freopen("1607.in","r",stdin);
freopen("1607.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++){
    scanf("%d",&a[i]);
    c[a[i]]++;
    mx=max(a[i],mx);
}
for(int i=1;i<=mx;i++){
    if(c[i]){
        for(int j=i;j<=mx;j+=i)s[j]+=c[i];
    }
}
for(int i=1;i<=n;i++)printf("%d\n",s[a[i]]-1);
return 0;
}
Category: BZOJ | Tags: bzoj | Read Count: 541

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com