hdu1695 GCD 容斥原理
Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = k. GCD(x, y) means the greatest common divisor of x and y. Since the number of choices may be very large, you're only required to output the total number of different number pairs.
Please notice that, (x=5, y=7) and (x=7, y=5) are considered to be the same.
Yoiu can assume that a = c = 1 in all test cases.
容斥原理的裸题
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll; const int maxn=2e5+; int pnum[maxn][],num[maxn]; void init(){
memset(pnum,,sizeof(pnum));
memset(num,,sizeof(num));
for(int i=;i<=;++i){
if(!num[i]){
pnum[i][++num[i]]=i;
for(int j=;i*j<=;++j){
pnum[i*j][++num[i*j]]=i;
}
}
}
} int main(){
init();
int T;
scanf("%d",&T);
for(int q=;q<=T;++q){
int a,b,c,d,k;
scanf("%d%d%d%d%d",&a,&b,&c,&d,&k);
if(!k){
printf("Case %d: 0\n",q);
continue;
}
a=b/k;b=d/k;
if(a>b){c=a;a=b;b=c;}
ll ans=;
if(a>=)ans+=b;
for(int p=;p<=a;++p){
ll res=;
for(int i=;i<(<<num[p]);++i){
int bit=;
ll mul=;
for(int j=;j<=num[p];++j){
if(i&(<<(j-))){
++bit;
mul*=pnum[p][j];
}
}
if(bit%)res+=(b/mul-(p-)/mul);
else res-=(b/mul-(p-)/mul);
}
ans+=b-(p-)-res;
}
printf("Case %d: %lld\n",q,ans);
}
return ;
}
hdu1695 GCD 容斥原理的更多相关文章
- 51nod 1678 lyk与gcd | 容斥原理
51nod 200题辣ψ(`∇´)ψ !庆祝! 51nod 1678 lyk与gcd | 容斥原理 题面 这天,lyk又和gcd杠上了. 它拥有一个n个数的数列,它想实现两种操作. 1:将 ai 改为 ...
- hdu1695 GCD 莫比乌斯反演做法+枚举除法的取值 (5,7),(7,5)看做同一对
/** 题目:hdu1695 GCD 链接:http://acm.hdu.edu.cn/status.php 题意:对于给出的 n 个询问,每次求有多少个数对 (x,y) , 满足 a ≤ x ≤ b ...
- [hdu1695] GCD ——欧拉函数+容斥原理
题目 给定两个区间[1, b], [1, d],统计数对的个数(x, y)满足: \(x \in [1, b]\), \(y \in [1, d]\) ; \(gcd(x, y) = k\) HDU1 ...
- HDU1695 GCD (欧拉函数+容斥原理)
F - GCD Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- HDU1695:GCD(容斥原理+欧拉函数+质因数分解)好题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题目解析: Given 5 integers: a, b, c, d, k, you're to ...
- hdu1695 GCD2 容斥原理 求x属于[1,b]与y属于[1,d],gcd(x,y)=k的对数。(5,7)与(7,5)看作同一对。
GCD Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Sub ...
- ACM学习历程—HDU1695 GCD(容斥原理 || 莫比乌斯)
Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = ...
- hdu1695 GCD
http://acm.hdu.edu.cn/showproblem.php?pid=16951 /** 大意: a<=x<=b , c<= y <= d ,求在此范围内 有多少 ...
- HDU 1695 GCD#容斥原理
http://acm.hdu.edu.cn/showproblem.php?pid=1695 翻译题目:给五个数a,b,c,d,k,其中恒a=c=1,x∈[a,b],y∈[c,d],求有多少组(x,y ...
随机推荐
- day22-python操作mysql2
数据库连接池 python编程中可以使用MySQLdb进行数据库的连接及诸如查询/插入/更新等操作,但是每次连接mysql数据库请求时,都是独立的去请求访问,相当浪费资源,而且访问数量达到一定数量时, ...
- 【资料搜集】Python学习
python学习手册 | 演道网 http://dev.go2live.cn/python/python%e5%ad%a6%e4%b9%a0%e6%89%8b%e5%86%8c.html
- Django 数据库连接配置(Oracle、Mysql)
一.Django Oracle连接配置 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.oracle', 'NAME': 'DEMO' ...
- [Leetcode 881]船救人 Boats to Save People 贪心
[题目] The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each b ...
- 在CentOS 7上使用Tripwire监控和检测修改的文件
在CentOS 7上使用Tripwire监控和检测修改的文件 Tripwire是一个免费的开源入侵检测系统(IDS). 它是用于监视和警告系统上文件更改的安全工具. Tripwire是一个功能强大的I ...
- 如何正确认识Docker Kubernetes 和 Apache Mesos
参考链接: http://geek.csdn.net/news/detail/229382
- 【转】strmbasd.lib(dllentry.obj) : error LNK2001: 无法解析的外部符号"int g_cTemplates"
加入了DirectShow的基类链接库后,如果此时编译就会出现以下编译错误: strmbasd.lib(wxutil.obj) : error LNK2019: 无法解析的外部符号 __imp__ti ...
- 前端框架VUE
Vue Vue近几年来特别的受关注,三年前的时候angularJS霸占前端JS框架市场很长时间,接着react框架横空出世,因为它有一个特性是虚拟DOM,从性能上碾轧angularJS,这个时候,vu ...
- 2019-03-26-day019-面向对象耦合与组合
作业 #对象的耦合 class Circle: def __init__(self,r): self.r = r def area(self): return 3.14*self.r**2 def p ...
- Strassen algorithm(O(n^lg7))
Let A, B be two square matrices over a ring R. We want to calculate the matrix product C as {\displa ...