# BZOJ1607 [Usaco2008 Dec]Patting Heads 轻拍牛头 【筛法】

## 输出格式

第1到N行，每行的输出表示第i头奶牛要拍打的牛数量．


## 输入样例

5 //有五个数,对于任一个数来说,其它的数有多少个是它的约数
2
1
2
3
4
INPUT DETAILS:

The 5 cows are given the numbers 2, 1, 2, 3, and 4, respectively.

## 输出样例

2
0
2
1
3
OUTPUT DETAILS:

The first cow pats the second and third cows; the second cows pats no cows;
etc.

## 题解

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u]; k != -1; k = ed[k].nxt)
using namespace std;
const int maxn = 100005,maxm = 1000005,INF = 1000000000;
inline int RD(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57) {if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57) {out = (out << 1) + (out << 3) + c - '0'; c = getchar();}
return out * flag;
}
int cnt[maxm],A[maxn],ans[maxm],N,Max = -1;
int main(){
N = RD();
REP(i,N) A[i] = RD(),Max = max(Max,A[i]),cnt[A[i]]++;
REP(i,Max)
if (cnt[i])
for (int j = i; j <= Max; j += i)
ans[j] += cnt[i];
REP(i,N) printf("%d\n",ans[A[i]] - 1);
return 0;
}

posted @ 2017-12-25 20:01  Mychael  阅读(143)  评论(0编辑  收藏  举报