hdu 1695 GCD (欧拉函数、容斥原理)
GCD
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7357 Accepted Submission(s): 2698
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.
Each case contains five integers: a, b, c, d, k, 0 < a <= b <= 100,000, 0 < c <= d <= 100,000, 0 <= k <= 100,000, as described above.
2 1 3 1 5 1 1 11014 1 14409 9
Case 1: 9 Case 2: 736427 Hint For the first sample input, all the 9 pairs of numbers are (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 5), (3, 4), (3, 5).
对于一个[1,n]的区间。我们能够用欧拉函数算出总对数。
- #include<stdio.h>
- #include<math.h>
- #include<string.h>
- #include<iostream>
- #include<algorithm>
- #include<vector>
- #define min(a,b) a<b?a:b
- #define max(a,b) a>b?
- a:b
- #define Max 100005
- #define LL __int64
- using namespace std;
- LL sum[Max],tot;
- int p[Max][20];
- int num[Max];
- void init()
- {
- sum[1]=1;
- for(int i=2;i<Max;i++)
- sum[i]=i;
- for(int i=2;i<Max;i++)
- if(sum[i]==i)
- for(int j=i;j<Max;j+=i)
- sum[j]=sum[j]/i*(i-1);
- }
- void init2()
- {
- LL x,k,i,j;
- for( i=1;i<=Max;i++)
- {
- x=i;k=0;
- for(j=2;j<=sqrt(i);j++)
- {
- if(x%j==0){
- while(x%j==0)x=x/j;
- // p[i].push_back(j);
- p[i][num[i]++]=j;
- }
- }
- if(x>1)p[i][num[i]++]=x;
- }
- }
- LL dfs(int n,int b,int x,int k)
- {
- LL ans=0;
- for(int i=x;i<k;i++)
- {
- ans+=b/p[n][i]-dfs(n,b/p[n][i],i+1,k);
- }
- return ans;
- }
- int main()
- {
- LL T,a,b,c,d,k;
- int i,j,t;
- init();
- init2();
- // printf("%I64d %I64d\n",sum[2],sum[3]);
- scanf("%I64d",&T);
- t=0;
- while(T--)
- {
- tot=0;
- t++;
- scanf("%I64d%I64d%I64d%I64d%I64d",&a,&b,&c,&d,&k);
- printf("Case %d: ",t);
- if(k==0){printf("0\n");continue;}
- b=b/k;
- d=d/k;
- int m;
- m=min(b,d);
- d=max(b,d);
- b=m;
- for(i=1;i<=b;i++)
- tot=tot+sum[i];
- for(i=b+1;i<=d;i++)
- {
- // printf("%d\n",p[i].size());
- tot+=b-dfs(i,b,0,num[i]);
- }
- printf("%I64d\n",tot);
- }
- return 0;
- }
hdu 1695 GCD (欧拉函数、容斥原理)的更多相关文章
- hdu 1695 GCD (欧拉函数+容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 1695 GCD 欧拉函数+容斥原理+质因数分解
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:在[a,b]中的x,在[c,d]中的y,求x与y的最大公约数为k的组合有多少.(a=1, a ...
- HDU 1695 GCD (欧拉函数,容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDU 1695 GCD 欧拉函数+容斥定理
输入a b c d k求有多少对x y 使得x在a-b区间 y在c-d区间 gcd(x, y) = k 此外a和c一定是1 由于gcd(x, y) == k 将b和d都除以k 题目转化为1到b/k 和 ...
- HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 1695 GCD 欧拉函数 + 容斥
http://acm.hdu.edu.cn/showproblem.php?pid=1695 要求[L1, R1]和[L2, R2]中GCD是K的个数.那么只需要求[L1, R1 / K] 和 [L ...
- HDU 2588 GCD (欧拉函数)
GCD Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status De ...
- [hdu1695] GCD ——欧拉函数+容斥原理
题目 给定两个区间[1, b], [1, d],统计数对的个数(x, y)满足: \(x \in [1, b]\), \(y \in [1, d]\) ; \(gcd(x, y) = k\) HDU1 ...
- HDU 1695 GCD(欧拉函数+容斥原理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:x位于区间[a, b],y位于区间[c, d],求满足GCD(x, y) = k的(x, ...
- HDU 1695 GCD (欧拉函数+容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- 正则效验url
上篇文章讲到多主题的解决方案:简单暴力的TP5多主题方案 为了简化配置,所以将域名前的协议 http/https 截取了. 后台配置时就需要效验配置的格式是否正确,需要用到的正则代码如下: /*** ...
- 题解 P3369 【【模板】普通平衡树】
在网上某篇神奇的教程和@codesonic 大佬的标程帮助下,我又肝完了Leafy Tree,跑过来写篇题解(好像以前写过一篇?) 什么是Leafy Tree? Leafy Tree由两种节点组成:辅 ...
- jquery.validate动态更改校验规则 【转】
有时候表单中有多个字段是相互关联的,以下遇到的就是证件类型和证件号码的关联,在下拉框中选择不同的证件类型,证件号码的值的格式都是不同的,这就需要动态的改变校验规则. <!DOCTYPE html ...
- Android Camera子系统之Linux C应用开发人员View
Android Camera HAL通过V4L2接口与内核Camera Driver交互.本文从Linux应用开发人员的角度审视Android Camera子系统. V4L2应用开发一般流程: 1. ...
- C语言:constkeyword、结构体
前几节内容的解说,主要是内存地址及指针的分析.这一节解说一下easy混淆的keywordconstant及结构体的知识. 一.constkeyword 1. 字符常量的指针 char const *p ...
- UVA 1415 - Gauss Prime(数论,高斯素数拓展)
UVA 1415 - Gauss Prime 题目链接 题意:给定a + bi,推断是否是高斯素数,i = sqrt(-2). 思路:普通的高斯素数i = sqrt(-1),推断方法为: 1.假设a或 ...
- java学习记录笔记--继承,super,Object类
继承: Java中的继承是单继承的. 1.子类拥有父类的全部属性和方法. 可是属性和方法的修饰符不能使private. 2.能够复用父类的代码. 方法的重写须要满足的条件: a.返回值类型 b.方法名 ...
- zzulioj--1778-- 和尚特烦恼4——有多少战斗力(gcd)
1778: 和尚特烦恼4--有多少战斗力 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 259 Solved: 123 SubmitStatusWe ...
- 14.mocha+should.js
转自http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutorial-of-examples.html 众所周知对于任何一个项目来说,做好单元测试都是必不 ...
- Django关于图片验证码显示笔记
.访问页面 /login/ - 内部需要创建一张图片,并且给用户返回 - 创建一个白板 Session存放验证码 .POST - 根据用户提交的数据与session里面比较 .登录界面 和 验证码 分 ...