[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 首先莫比乌斯函数的一些性质可以看<初等数论>或<具 ...
随机推荐
- python实现K聚类算法
参考:<机器学习实战>- Machine Learning in Action 一. 基本思想 聚类是一种无监督的学习,它将相似的对象归到同一簇中.它有点像全自动分类.聚类方法几乎可以应 ...
- Alpha冲刺Day3
Alpha冲刺Day3 一:站立式会议 今日安排: 我们把项目大体分为四个模块:数据管理员.企业人员.第三方机构.政府人员.数据管理员这一模块,数据管理员又可细分为两个模块:基础数据管理和风险信息管理 ...
- 设计模式NO.2
设计模式NO.2 本次博客内容为第二次设计模式的练习.根据老师的要求完成下列题目: 题目1 如果需要开发一个跨平台视频播放器,可以在不同操作系统平台(如Windows.Linux.UNIX等)上播放多 ...
- 基本数据类型 Symbol
ES6 规范之前, JavaScript 一共有六种数据类型,分别是五种基本数据类型: string . number , boolean , null , undefined ,和一种引用数据类型: ...
- service层报错找不到方法Invalid bound statement (not found)
报错信息如下 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.imooc.se ...
- UML开发工具Rose ralation的破解安装,
UML开发工具Rose ralation的在windows764破解安装, 安装下载还可以参考:http://www.cnblogs.com/leaven/p/3718361.html 跟大家分享怎么 ...
- Web Api 使用模型验证
public class Person { public int Id { get; set; } [Required(ErrorMessage = "姓名不能为空啊啊啊!")] ...
- List集合就这么简单【源码剖析】
前言 声明,本文用得是jdk1.8 前一篇已经讲了Collection的总览:Collection总览,介绍了一些基础知识. 现在这篇主要讲List集合的三个子类: ArrayList 底层数据结构是 ...
- Kompose: Docker-compose 到 Kubernetes 的迁移工具
Docker 让每个人都能够从 Docker Registry 启动一个打包好的 Docker 应用.Docker-Compose在Docker基础上解决了多容器应用之间的依赖启动问题. Docker ...
- Docker学习笔记 - Docker Compose 脚本命令
Docker Compose 配置文件包含 version.services.networks 三大部分,最关键的是 services 和 networks 两个部分, version: '2' se ...