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 ...
随机推荐
- learning ddr mode register MR0
- python中字典常用的方法
#定义一个空字典: a={ } 定义一个字典: d={'age':18} #增加一个元素: d['age']=20 d[k]=v d.setdefault('age',18) d.setde ...
- JXL生成Excel,并提供下载(1:生成Excel)
public String exportExcel(long id) { String preeReviewName = "文件名"; String filePath = 路径名; ...
- vue-router-3-嵌套路由
<div id="app"> <router-view></router-view> </div> const User = { t ...
- eclipse server和tomcat的区别,将server的部署目录改到自己安装的tomcat中及如何设置tomcat用户
转:http://www.cnblogs.com/Yogurshine/archive/2013/06/05/3118525.html 一.发现问题(如果不把项目部署到tomcat的webapp目录下 ...
- BOM浏览器操作对象
BOM定义 一.定时器 1) 定时器1:setInterval() 2)一次性定时器 二.offset.scroll.client
- 重载方法写delete请求
#encoding=utf-8#__author__="Lanyangyang" import unittestimport requestsimport json # This ...
- 软件开发模式,DevOps
参考文献:http://www.cnblogs.com/jetzhang/p/6068773.html 历史回顾 为了能够更好的理解什么是DevOps,我们很有必要对当时还只有程序员(此前还没有派生出 ...
- [深入理解Java虚拟机]<自动内存管理>
Overview 走近Java:介绍Java发展史 第二部分:自动内存管理机制 程序员把内存控制的权利交给了Java虚拟机,从而可以在编码时享受自动内存管理.但另一方面一旦出现内存泄漏和溢出等问题,就 ...
- wait_activity
wait_activity(self, activity, timeout, interval=1): android特有的 返回的True 或 False :Agrs: - activity - 需 ...