# [USACO08DEC]拍头Patting Heads 数学 BZOJ 1607

## 题目描述

It's Bessie's birthday and time for party games! Bessie has instructed the N (1 <= N <= 100,000) cows conveniently numbered 1..N to sit in a circle (so that cow i [except at the ends] sits next to cows i-1 and i+1; cow N sits next to cow 1). Meanwhile, Farmer John fills a barrel with one billion slips of paper, each containing some integer in the range 1..1,000,000.

Each cow i then draws a number A_i (1 <= A_i <= 1,000,000) (which is not necessarily unique, of course) from the giant barrel. Taking turns, each cow i then takes a walk around the circle and pats the heads of all other cows j such that her number A_i is exactly

divisible by cow j's number A_j; she then sits again back in her original position.

The cows would like you to help them determine, for each cow, the number of other cows she should pat.

## 输入输出格式

* Line 1: A single integer: N

* Lines 2..N+1: Line i+1 contains a single integer: A_i

* Lines 1..N: On line i, print a single integer that is the number of other cows patted by cow i.

## 输入输出样例

5
2
1
2
3
4


2
0
2
1
3


## 说明

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

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

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 400005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-4
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;

inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
}

ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; }

/*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/

int n;
int a[maxn];
//map<int, int>mp;
int mp[1000003];
int main() {
//	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
n = rd();
for (int i = 1; i <= n; i++)a[i] = rd(),mp[a[i]]++;
//	for (int i = 1; i <= n; i++)
for (int i = 1; i <= n; i++) {
int sum = 0;
for (int j = 1; j <= sqrt(a[i]); j++) {
if (a[i] % j == 0)sum += mp[j] + mp[a[i] / j];
}
if ((int)sqrt(a[i])*(int)sqrt(a[i]) == a[i])
sum -= mp[(int)sqrt(a[i])];
printf("%d\n", sum - 1);
}
return 0;
}


posted @ 2019-01-27 22:01  NKDEWSM  阅读(107)  评论(0编辑  收藏  举报