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 ...
随机推荐
- Vue + Element UI 实现权限管理系统(搭建开发环境)
技术基础 开发之前,请先熟悉下面的4个文档 vue.js2.0中文, 优秀的JS框架 vue-router, vue.js 配套路由 vuex,vue.js 应用状态管理库 Element,饿了么提供 ...
- jquery插件artTxtCount输入字数限制,并提示剩余字数
工作中用到,需要批量处理下 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...
- js中 offset /client /scroll总结
offset家族(只能读取,不能操作): offsetLeft:元素的边框的外边缘距离与已定位的父容器(offsetparent)的左边距离(就是子元素左边框到父元素左边框的距离). offsetTo ...
- S2 深入.NET和C#编程 机试测试错题积累
机试第一题: //创建文件流(路径 模式) FileStream fa = new FileStream(@"D:\\S2第一次全文 ...
- [Linux]Linux下rsync服务器和客户端配置
一.rsync简介 Rsync(remote sync)是UNIX及类UNIX平台下一款神奇的数据镜像备份软件,它不像FTP或其他文件传输服务那样需要进行全备份,Rsync可以根据数据的变化进行差异( ...
- cv::ACCESS_MASK指定不明确的错误
今天想实现在opencv下使用模拟按键,结果出现cv::ACCESS_MASK指定不明确的错误,查找得到如下原因: 在winnt.h里面有一个cv的命名空间,同样定义了一个ACCESS_MASK,跟o ...
- spring源码研究1 如何导入源码
环境 jdk8 windows8 1.下载源码 https://github.com/spring-projects/spring-framework 2.编译为eclipse项目 源码下载无法直接导 ...
- centos/7下安装mysql5.7
本文参考自:https://blog.csdn.net/fanshujuntuan/article/details/78077433 背景:在ubuntu下用vagrant搭建了一个集群环境, 每个虚 ...
- mysql 数据类型day43
数据类型 一数值类型 1 整数类型 默认是有符号的 unsigned 没有符号 zerofill0t 小整数 TINYINT [(m)] 1个字节 8bit 2**8 256 m 最多3位 最低 -1 ...
- python分析nginx自定义日志
# -*- coding:utf-8 -*- import datetimeimport re logfile = '''192.168.23.43 - 2017-12-14:00:14:41 /se ...