Description

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 Ai (1 ≤ Ai ≤ 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 Ai is exactly divisible by cow j's number Aj; 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.

Input

* Line 1: A single integer: N

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

Output

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

Sample Input

5
2
1
2
3
4

Sample Output

2
0
2
1
3

Hint

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.

题目大概的意思就是说牛1手上的数字可以去整除其他牛的数字,则可以去爆他狗头。
一开始我是想说一一去枚举的,从一找到牛手上的数可以整除的数,去加他,但发现超时。
于是有了这种思路,我从1到牛手上的最大的数枚举,if这个数字是有的,那这个数的倍数都加上他的次数;
AC 代码
#include<stdio.h>
int num1[]={};
int num2[]={};
int a[];
int main()
{
int n,i,mix=,j; scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%d",&a[i]);
num1[a[i]]++; } for(i=;i<=n;i++)
if(mix<a[i])
mix=a[i]; for(i=;i<=mix;i++)
{ if(num1[i]!=)
for(j=i;j<=mix;j=j+i)
{
num2[j]=num2[j]+num1[i]; }
} for(i=;i<=n;i++)
printf("%d\n",num2[a[i]]-);
}

Patting Heads的更多相关文章

  1. BZOJ-1607 [Usaco2008 Dec]Patting Heads 轻拍牛头 筛法+乱搞

    1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Time Limit: 3 Sec Memory Limit: 64 MB Submit: 1383 Solved: 7 ...

  2. BZOJ 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 筛法

    1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lyds ...

  3. BZOJ 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头

    1607: [Usaco2008 Dec]Patting Heads 轻拍牛头 Description   今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏.     贝茜让N(1≤N≤10 ...

  4. bzoj1607 / P2926 [USACO08DEC]拍头Patting Heads

    P2926 [USACO08DEC]拍头Patting Heads 把求约数转化为求倍数. 累计每个数出现的个数,然后枚举倍数累加答案. #include<iostream> #inclu ...

  5. 浅谈桶排思想及[USACO08DEC]Patting Heads 题解

    一.桶排思想 1.通过构建n个空桶再将待排各个元素分配到每个桶.而此时有可能每个桶的元素数量不一样,可能会出现这样的情况:有的桶没有放任何元素,有的桶只有一个元素,有的桶不止一个元素可能会是2+: 2 ...

  6. [bzoj1607][Usaco2008 Dec]Patting Heads 轻拍牛头_筛法_数学

    Patting Heads 轻拍牛头 bzoj-1607 Usaco-2008 Dec 题目大意:题目链接. 注释:略. 想法:我们发现,位置是没有关系的. 故,我们考虑将权值一样的牛放在一起考虑,c ...

  7. 洛谷 P2926 [USACO08DEC]拍头Patting Heads

    P2926 [USACO08DEC]拍头Patting Heads 题目描述 It's Bessie's birthday and time for party games! Bessie has i ...

  8. [Usaco2008 Dec]Patting Heads

    It's Bessie's birthday and time for party games! Bessie has instructed the N (1 <= N <= 100,00 ...

  9. [USACO08DEC]拍头Patting Heads 数学 BZOJ 1607

    题目描述 It's Bessie's birthday and time for party games! Bessie has instructed the N (1 <= N <= 1 ...

随机推荐

  1. .net 4 安装未成功,无意中的解决办法!

    公司 电脑是chost的系统,由于使用时间过长,重装纯净版系统的话,代价太大,故网上寻求各种解决办法! 安装.net 4 总是失败,查看百度,各种: WIN7系统哈哈跟我的问题一样,我的刚才解决了:1 ...

  2. hive删除表报错:Specified key was too long; max key length&nb

    我是在hive删除表的时候出现这个错误的,看到这个错误应该就知道是字符集错误. 但是我用​ alter database hive character set latin1; 这个命令将其改成拉丁之后 ...

  3. python学习笔记(1)python下载及运行

    进入https://www.python.org/官网下载python,根据需要选择2.*或3.*版本 安装完将安装目录添加到环境变量path中 运行cmd,输入python出现版本号即配置成功 下载 ...

  4. ssh整合思想

    整合过程:

  5. resize和reserve的区别

    转自http://blog.csdn.net/jackywgw/article/details/6248342 首先必须弄清楚两个概念: 1.capacity 指容器在分配新的存储空间之前能存储的元素 ...

  6. Entity Framework Tutorial Basics(14):Choose development approach

    Choose development approach with Entity Framework: We have seen Code-first, Model-first and Database ...

  7. C++--VECTOR的简单应用

    在c++中,vector是一个十分有用的容器,下面对这个容器做一下总结. 1 基本操作 (1)头文件#include<vector>. (2)创建vector对象,vector<in ...

  8. 《Head First Servlets & JSP》-10-定制标记开发

    标记文件:很想include,但是比include更好 建立和使用标记文件的最简方法 取一个被包含文件(如Header.jsp),把它重命名为带有一个.tag扩展名(Header.tag): 把标记文 ...

  9. 开启wifi后不能ping通本机 Cann't ping the local PC while start a wlan

    问题如题:今天发现一个问题,测试本机ip时候有时候总是获取失败,后来才发现是wifi共享软件导致的缘故. 本来呢?我买的是小米wifi,但是小米wifi对应的客户端不是很好用,动不动就启动失败,不要问 ...

  10. HTML完全使用详解 PDF扫描版​

    <HTML完全使用详解>根据网页制作的实际特点和目前市场需要,全面系统地介绍了最新的HTML4.01.丰富的实例贯穿全书,能帮助您全面掌握HTML,而且本书所有实例均可直接修改使用,可以提 ...