3067: 【普及/提高-】【P2926】Patting Heads S
内存限制:128 MB
时间限制:1.000 S
评测方式:文本比较
命题人:
提交:1
解决:1
题目描述
今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏。
贝茜让 () 头奶牛坐成一个圈。除了 号与 号奶牛外, 号奶牛与 号和 号奶牛相邻。 号奶牛与 号奶牛相邻。农夫约翰用很多纸条装满了一个桶,每一张包含了一个不一定是独一无二的 到 的数字。
接着每一头奶牛 从柄中取出一张纸条 。每头奶牛轮流走上一圈,同时拍打所有手上数字能整除在自己纸条上的数字的牛的头,然后做回到原来的位置。牛们希望你帮助他们确定,每一头奶牛需要拍打的牛。
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.
输入
* 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
提示
#include<bits/stdc++.h> using namespace std; #define maxn 1000010 int n,a[maxn],c[maxn],w[maxn]; //数列中的数字,数字记数,计算贡献 int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]),c[a[i]]++; for(int i=1;i<=1000000;i++) for(int j=i;j<=1000000;j+=i) w[j]+=c[i]; //i这个数会对j产生c[j]的贡献 for(int i=1;i<=n;i++) printf("%d\n",w[a[i]]-1); //要减掉a[i]对自己的贡献 return 0; }