[POI2007]ZAP-Queries
题目描述
Byteasar the Cryptographer works on breaking the code of BSA (Byteotian Security Agency). He has alreadyfound out that whilst deciphering a message he will have to answer multiple queries of the form"for givenintegers ,
and
, find the number of integer pairs
satisfying the following conditions:
,
,
, where
is the greatest common divisor of
and
".
Byteasar would like to automate his work, so he has asked for your help.
TaskWrite a programme which:
reads from the standard input a list of queries, which the Byteasar has to give answer to, calculates answers to the queries, writes the outcome to the standard output.
FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd(x,y)=d。作为FGD的同学,FGD希望得到你的帮助。
输入输出格式
输入格式:
The first line of the standard input contains one integer (
),denoting the number of queries.
The following lines contain three integers each:
,
and
(
), separated by single spaces.
Each triplet denotes a single query.
输出格式:
Your programme should write lines to the standard output. The
'th line should contain a single integer: theanswer to the
'th query from the standard input.
输入输出样例
- 2
- 4 5 2
- 6 4 3
- 3
- 2
题解:莫比乌斯反演+分块
其实我写过一边博客上的题跟这个几乎一摸一样,而且这个还不要容斥
在这里偷个懒,贴出题目 [HAOI2011]Problem b
本题卡常数,所以能不用long long就不用
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<cstring>
- using namespace std;
- typedef long long lol;
- lol ans;
- int prime[];
- lol mu[];
- int n,m,d,tot;
- bool vis[];
- void mobius()
- {int i,j;
- mu[]=;
- for (i=;i<=;i++)
- {
- if (vis[i]==)
- {
- tot++;
- prime[tot]=i;
- mu[i]=-;
- }
- for (j=;j<=tot,i*prime[j]<=;j++)
- {
- vis[i*prime[j]]=;
- if (i%prime[j]==)
- {
- mu[i*prime[j]]=;
- break;
- }
- mu[i*prime[j]]=-mu[i];
- }
- }
- for (i=;i<=;i++)
- mu[i]+=mu[i-];
- }
- void solve()
- {int i;
- int pos=;
- int r=min(n,m);
- for (i=;i<=r;i=pos+)
- {
- if (n/(n/i)>m/(m/i))
- pos=m/(m/i);
- else pos=n/(n/i);
- ans+=(mu[pos]-mu[i-])*(long long)(n/i)*(long long)(m/i);
- }
- }
- int main()
- {int T;
- cin>>T;
- mobius();
- while (T--)
- {
- scanf("%d%d%d",&n,&m,&d);
- n=n/d;m=m/d;
- ans=;
- solve();
- printf("%lld\n",ans);
- }
- }
[POI2007]ZAP-Queries的更多相关文章
- BZOJ 1101: [POI2007]Zap
1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2262 Solved: 895[Submit][Status] ...
- [BZOJ1101][POI2007]Zap
[BZOJ1101][POI2007]Zap 试题描述 FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd ...
- BZOJ 1101: [POI2007]Zap( 莫比乌斯反演 )
求 answer = ∑ [gcd(x, y) = d] (1 <= x <= a, 1 <= y <= b) . 令a' = a / d, b' = b / d, 化简一下得 ...
- BZOJ1101: [POI2007]Zap(莫比乌斯反演)
1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2951 Solved: 1293[Submit][Status ...
- 莫比乌斯反演学习笔记+[POI2007]Zap(洛谷P3455,BZOJ1101)
先看一道例题:[POI2007]Zap BZOJ 洛谷 题目大意:$T$ 组数据,求 $\sum^n_{i=1}\sum^m_{j=1}[gcd(i,j)=k]$ $1\leq T\leq 50000 ...
- [POI2007]Zap
bzoj 1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Descriptio ...
- Bzoj1101: [POI2007]Zap 莫比乌斯反演+整除分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 莫比乌斯反演 1101: [POI2007]Zap 设 \(f(i)\) 表示 \(( ...
- BZOJ1101 POI2007 Zap 【莫比乌斯反演】
BZOJ1101 POI2007 Zap Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b, ...
- 1101: [POI2007]Zap(莫比乌斯反演)
1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MB Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定 ...
- 【BZOJ】1101: [POI2007]Zap(莫比乌斯+分块)
http://www.lydsy.com/JudgeOnline/problem.php?id=1101 无限膜拜数论和分块orz 首先莫比乌斯函数的一些性质可以看<初等数论>或<具 ...
随机推荐
- Week03-面向对象入门
1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词,如类.对象.封装等 类 对象 封装 继承 覆盖 重载 构造函数 static public private toString f ...
- highcharts 具体参数详解
<script type="text/javascript" src="js/jquery.min.js"></script> < ...
- 第二篇:利用shell脚本执行webservice请求——基于soap
1. 项目背景 以往我们在开发基于webservice的项目中,我们总习惯于直接使用webservice的一些框架,如Axis,axis2和Xfire等.框架的好处是将webservice所涉及到的s ...
- windows 10下通过python3.6成功搭建jupyter 服务器
最近通过python学习爬虫技术,发现一个工具jupyter notebook很不错,该工具明显优势通过浏览器可以输入多行python代码,支持在线运行以及运行结果保存功能,在线验证python小模块 ...
- 彻底搞懂shell的高级I/O重定向
本文目录: 1.1 文件描述符(file description,fd) 1.2 文件描述符的复制 1.3 重定向顺序很重要:">file 2>&1"和&quo ...
- Python扩展模块——selenium的使用(定位、下载文件等)
想全面的使用selenium可以下载<selenium 2自动化测试实战-基于Python语言>PDF的电子书看看 我使用到了简单的浏览器操作,下载文件等功能... 推荐使用firefox ...
- 查找git ignore的追踪
前言 版本控制说简单也简单,说复杂也困难的多.作为开发者,最基础的版本管理和团队协作的功能必须掌握.而其他一些相关的信息也可以了解下.比如,这次就有同事遇到了问题. 遇到的问题 在windows下,往 ...
- emqtt 试用(六)系统主题
$SYS-系统主题 EMQ 消息服务器周期性发布自身运行状态.MQTT 协议统计.客户端上下线状态到 $SYS/ 开头系统主题. $SYS 主题路径以 "$SYS/brokers/{node ...
- Spring知识点回顾(06)Profile 和 条件注解 @Conditional
1.设定环境中的active profiles 如:DispatcherServerlet的init-param spring.profiles.active=production spring.pr ...
- python、java实现二叉树,细说二叉树添加节点、深度优先(先序、中序、后续)遍历 、广度优先 遍历算法
数据结构可以说是编程的内功心法,掌握好数据结构真的非常重要.目前基本上流行的数据结构都是c和c++版本的,我最近在学习python,尝试着用python实现了二叉树的基本操作.写下一篇博文,总结一下, ...