题目描述

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.

今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏.

贝茜让N(1≤N≤100000)头奶牛坐成一个圈.除了1号与N号奶牛外,i号奶牛与i-l号和i+l号奶牛相邻.N号奶牛与1号奶牛相邻.农夫约翰用很多纸条装满了一个桶,每一张包含了一个不一定是独一无二的1到1,000,000的数字.

接着每一头奶牛i从柄中取出一张纸条Ai.每头奶牛轮流走上一圈,同时拍打所有手上数字能整除在自己纸条上的数字的牛的头,然后做回到原来的位置.牛们希望你帮助他们确定,每一头奶牛需要拍打的牛.

输入输出格式

输入格式:

* 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.

输入输出样例

输入样例#1: 复制

5
2
1
2
3
4

输出样例#1: 复制

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;
}

转载于:https://www.cnblogs.com/zxyqzy/p/10328163.html

[USACO08DEC]拍头Patting Heads 数学 BZOJ 1607相关推荐

  1. [USACO08DEC]Patting Heads S题解

    这里附上题目链接:[USACO08DEC]Patting Heads S. ~~手动分割~~ 题目 思路解析 1.暴力搜索 将每头牛拿的数字存下. 分别将每头牛拿的数作为被除数,逐一检查剩下的n-1头 ...

  2. 前端 - token 是什么?为什么每次请求头(HEADS)里要携带它?___请求时,为什么要携带token?

    前端 - token 是什么?为什么每次请求头(HEADS)里要携带它? Token token 是客户端频繁向服务器端请求数据,服务器频繁的去数据库查询用户名和密码进行对比,判断用户名和密码正确与否 ...

  3. 一拍是多少秒 计算机制音乐,E哥谈如何计算音乐的拍数及每拍时值是多少数学好学音乐有帮助吗...

    一.怎样计算音乐的节拍? 这个网上有很多回答,包括这里问答也有很多回答.都很对.我就不重复说了.我只举一个例子,直接说明. 1.这里只说假定一个1/4音符表示一拍. 也就是上图A表示的是四分音符,也就 ...

  4. 【洛谷2926/BZOJ1607】[USACO08DEC]Patting Heads拍头(筛法)

    题目: 洛谷2926 (截止至本博客发表时,BZOJ1607题面有误,正确题面请到洛谷2926查看) 分析: = 一句话题意:给定\(n\)个数\(\{a_i\}\),求对于每个\(a_i\)有多少个 ...

  5. BZOJ 1607 [Usaco2008 Dec]Patting Heads 轻拍牛头:统计 + 筛法【调和级数】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1607 题意: 给你n个数,问你除a[i]之外,有多少个数是a[i]的约数. 题解: ans ...

  6. 【BZOJ】1607: [Usaco2008 Dec]Patting Heads 轻拍牛头

    [算法]模拟 #include<cstdio> #include<algorithm> using namespace std; const int maxn=100010,m ...

  7. bzoj 1607: [Usaco2008 Dec]Patting Heads 轻拍牛头

    翻过来考虑影响,考虑多少数是他的倍数. 1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 ...

  8. bzoj1607: [Usaco2008 Dec]Patting Heads 轻拍牛头

    傻逼题...(然而一开始题意都不懂) #include<cstdio> #include<cstring> using namespace std; int n,a[11000 ...

  9. BZOJ1607 [Usaco2008 Dec]Patting Heads 轻拍牛头 筛法

    欢迎访问~原文出处--博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1607 题意概括 给出n个数,每一个数字<1000000,对于每一个数,让你求剩余的n-1个数 ...

最新文章

  1. 线性排序算法分析总结
  2. Java语言程序设计实验指导_《java语言程序设计》上机实验指导手册(4).doc
  3. Shell脚本中循环until命令用法笔记
  4. CAS的安装与配置(一)服务器端配置
  5. 人工智能ai以算法为基础_智能扬声器和AI将为您的医师带来超强能力
  6. 收藏 | 10个重要问题概览Transformer全部内容
  7. Modelarts与无感识别技术生态总结(浅出版)
  8. 面向机器学习的特征工程 八、自动化特征提取器:图像特征提取和深度学习
  9. 编译hadoop源码遇到问题 及时解决
  10. python的模块和类_Python 模块和类
  11. ios识别人脸自动拍照_ios人脸拍照识别
  12. 几款好用的敏捷开发工具
  13. 在html中图文结合的怎么写,字形合一,网页设计中的图文配
  14. dede 表单必填_织梦给自定义表单增加必填功能,织梦表单必填设置
  15. 淘宝客微信机器人接口API开发
  16. Character.UnicodeBlock中cjk的说明
  17. 怎么用python启动谷歌浏览器_Selenium 基于python 安装以及配置谷歌浏览器启动
  18. 赵雅智:android发彩信操作
  19. 正余弦函数的复指数表示
  20. 如何实现网站事件统计与事件分析

热门文章

  1. C语言程序设计 笔试考试,试题样卷
  2. 基于CSS3实现元素宽度向两侧延伸
  3. 7-11 数列求和-加强版 (20 分)
  4. ResultSet的getDate()、getTime()和getTimestamp()比较
  5. finalshell连接失败解决方法_iPhone热点连不上?教你网络连接失败或断线的解决办法...
  6. 数据结构-在O(1)时间删除链表节点
  7. Spring MVC对象转换说明
  8. Vue小案例 之 商品管理------创建页面与部分数据
  9. MySQL JSON 类型数据操作
  10. java开发过程中几种常用算法