首页 技术 正文
技术 2022年11月13日
0 收藏 468 点赞 5,012 浏览 1747 个字

题目描述

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 [POI2007]ZAP-Queries[POI2007]ZAP-Queries and [POI2007]ZAP-Queries, find the number of integer pairs [POI2007]ZAP-Queries satisfying the following conditions:

[POI2007]ZAP-Queries,[POI2007]ZAP-Queries,[POI2007]ZAP-Queries, where [POI2007]ZAP-Queries is the greatest common divisor of [POI2007]ZAP-Queries and [POI2007]ZAP-Queries“.

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 [POI2007]ZAP-Queries ([POI2007]ZAP-Queries),denoting the number of queries.

The following [POI2007]ZAP-Queries lines contain three integers each: [POI2007]ZAP-Queries[POI2007]ZAP-Queries and [POI2007]ZAP-Queries([POI2007]ZAP-Queries), separated by single spaces.

Each triplet denotes a single query.

输出格式:

Your programme should write [POI2007]ZAP-Queries lines to the standard output. The [POI2007]ZAP-Queries‘th line should contain a single integer: theanswer to the [POI2007]ZAP-Queries‘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);
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,494
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297