题目描述

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.

输入输出样例

输入样例#1:

2
4 5 2
6 4 3
输出样例#1:

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的更多相关文章

  1. BZOJ 1101: [POI2007]Zap

    1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2262  Solved: 895[Submit][Status] ...

  2. [BZOJ1101][POI2007]Zap

    [BZOJ1101][POI2007]Zap 试题描述 FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd ...

  3. BZOJ 1101: [POI2007]Zap( 莫比乌斯反演 )

    求 answer = ∑ [gcd(x, y) = d] (1 <= x <= a, 1 <= y <= b) . 令a' = a / d, b' = b / d, 化简一下得 ...

  4. BZOJ1101: [POI2007]Zap(莫比乌斯反演)

    1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2951  Solved: 1293[Submit][Status ...

  5. 莫比乌斯反演学习笔记+[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 ...

  6. [POI2007]Zap

    bzoj 1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Descriptio ...

  7. Bzoj1101: [POI2007]Zap 莫比乌斯反演+整除分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 莫比乌斯反演 1101: [POI2007]Zap 设 \(f(i)\) 表示 \(( ...

  8. BZOJ1101 POI2007 Zap 【莫比乌斯反演】

    BZOJ1101 POI2007 Zap Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b, ...

  9. 1101: [POI2007]Zap(莫比乌斯反演)

    1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MB Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定 ...

  10. 【BZOJ】1101: [POI2007]Zap(莫比乌斯+分块)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1101 无限膜拜数论和分块orz 首先莫比乌斯函数的一些性质可以看<初等数论>或<具 ...

随机推荐

  1. Alpha冲刺No.6

    站立式会议 继续页面设计 在安卓内构件数据库相应类 解决摄像头.照片的使用的异常问题 二.实际项目进展 页面设计完成百分80 类架构完成 在虚拟机中,能够完成摄像头的调用和程序的使用 三.燃尽图 四. ...

  2. 项目Alpha冲刺Day11

    一.会议照片 二.项目进展 1.今日安排 熟悉框架的使用以及编写用户查看的界面以及该页面内的操作. 2.问题困难 全局的日期转换出现问题,在序列化的时候是按照配置来的,但是反序列化的时候就错了,问题待 ...

  3. c++第0次作业

    1.你认为大学的学习生活.同学关系.师生应该是怎样? 随着大学生活的慢慢到来,我开始领悟到大学并不是自由的天堂,相反,我们更加的走进社会这个牢笼.在这个牢笼中有着从前的我们并不需要在意和考虑的规则与问 ...

  4. C程序第一次作业

    1-1 计算两数的和与差 1 设计思路 (1)主要描述题目算法 第一步:利用指针psum接收sum的地址,指针pdiff接收diff的地址,因此 * psum为sum, * pdiff为diff. 第 ...

  5. win7开启wifi

    在启用本地共享连接时,出现的错误! 我已经建了一个无线临时网络,来启用共享用来上网的!Internet连接共享访问被启用时,出现了一个错误(null)?而且这错误也会在系统日志里留下记录,都是些莫名其 ...

  6. Python 单向循环链表

    操作 is_empty() 判断链表是否为空 length() 返回链表的长度 travel() 遍历 add(item) 在头部添加一个节点 append(item) 在尾部添加一个节点 inser ...

  7. 《高级软件测试》web测试实践--12月30日记录

    考完数学,我们正式开始web测试实践的作业,今天,我们主要进行了方案的选择和人员的分工.任务计划和安排如上图所示. 任务进展:完成题目选择和人员分工: 遇到问题:暂无: 下一步任务:完成软件评测.用户 ...

  8. Hibernate之深入Hibernate的配置文件

    1.创建Configuration类的对象 Configuration类的对象代表了应用程序到SQL数据库的映射配置.Configuration类的实例对象,提供一个buildSessionFacto ...

  9. mint-ui在vue中的使用。

    首先放上mint-ui中文文档 近来在使用mint-ui,发现部分插件在讲解上并不是很详细,部分实例找不到使用的代码.github上面的分享,里面都是markdown文件,内容就是网上的文档 刚好自己 ...

  10. Mego开发文档 - 复杂查询

    复杂查询 Mego 还支持一些更高级的LLINQ查询写法,本文只列出一部分. 分组汇总查询 using (var db = new OrderManageEntities()) { var query ...