[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 首先莫比乌斯函数的一些性质可以看<初等数论>或<具 ...
随机推荐
- 20162302 实验一《Java开发环境的熟悉》实验报告
实 验 报 告 课程:程序设计与数据结构 姓名:杨京典 班级:1623 学号:20162302 实验名称:Java开发环境的熟悉 实验器材:装有Ubuntu的联想拯救者80RQ 实验目的与要求:1.使 ...
- python中使用flask时遇到的markupsafe._compat包缺失的问题与解决
环境:windows7 + python3.6.0 在尝试使用python的flask时,按照flask的tutorial操作,装好flask.venv后,对tutorial中的hello.py进行运 ...
- 2017-2018-1 1623 bug终结者 冲刺003
bug终结者 冲刺003 by 王旌含 今日任务:优化界面布局,提供图片素材 需求 app图标.主界面图.主界面中按钮图:选择关卡图.关卡按键图:游戏中的小人.箱子.地板.墙.目的地:方向按钮:重置按 ...
- C语言——第十四、十五周作业
题目 题目一:交换最小值和最大值 1.实验代码 #include<stdio.h> int main() { ; int i , n; int a[N]; int x , y; scanf ...
- django BBS
https://github.com/triaquae/py_training/tree/master/OldboyBBS2 http://www.cnblogs.com/zhming26/p/592 ...
- visualVM使用jstatd和jmx连接远程jvm及遇到的问题解决
visualVM使用jstatd和jmx连接远程jvm及遇到的问题解决 JMX方式: 编辑Tomact里bin目录的catalina.sh . 在其头部加入 JAVA_OPTS=" -Dco ...
- bzoj千题计划244:bzoj3730: 震波
http://www.lydsy.com/JudgeOnline/problem.php?id=3730 点分树内对每个节点动态维护2颗线段树 线段树以距离为下标,城市的价值为权值 对于节点x的两棵线 ...
- JS 转换数据类型
JavaScript 是一种动态数据类型语言,变量是没有类型的,可以随机赋予任意值,若变量要转换数据类型,有两种办法:隐式转换和显式转换. 隐式转换可转换为字符串(将一个值加上字符串) 数字(在值的前 ...
- EasyUI 主布局整合。
博文学习地址:http://www.cnblogs.com/xishuai/p/3620327.html html: <%@ Page Language="C#" AutoE ...
- nodejs 全局变量
1.全局对象 所有模块都可以调用 1)global:表示Node所在的全局环境,类似于浏览器中的window对象. 2)process:指向Node内置的process模块,允许开发者与当前进程互动. ...