The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the largest divisor common to a and b,For example,(1,2)=1,(12,18)=6. 

(a,b) can be easily found by the Euclidean algorithm. Now Carp is considering a little more difficult problem: 

Given integers N and M, how many integer X satisfies 1<=X<=N and (X,N)>=M.

Input

The first line of input is an integer T(T<=100) representing the number of test cases. The following T lines each contains two numbers N and M (2<=N<=1000000000, 1<=M<=N), representing a test case.

Output

For each test case,output the answer on a single line.

Sample Input

  1. 3
  2. 1 1
  3. 10 2
  4. 10000 72

Sample Output

  1. 1
  2. 6
  3. 260

代码:

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6. long long int oula(int n)
  7. {
  8. long long int res=1;
  9. for(int t=2;t*t<=n;t++)
  10. {
  11. if(n%t==0)
  12. {
  13. n/=t;
  14. res*=t-1;
  15. while(n%t==0)
  16. {
  17. n/=t;
  18. res*=t;
  19. }
  20. }
  21. }
  22. if(n>1)
  23. {
  24. res*=n-1;
  25. }
  26. return res;
  27. }
  28. int main()
  29. {
  30. int n;
  31. cin>>n;
  32. int a,b;
  33. long long int ans;
  34. for(int t=0;t<n;t++)
  35. {
  36. ans=0;
  37. scanf("%d%d",&a,&b);
  38. int j;
  39. for( j=1;j*j<a;j++)
  40. {
  41. if(a%j==0)
  42. {
  43. if(j>=b)
  44. {
  45. ans+=oula(a/j);
  46. }
  47. if(a/j>=b)
  48. {
  49. ans+=oula(j);
  50. }
  51. }
  52. }
  53. if(j*j==a&&j>=b)
  54. {
  55. ans+=oula(j);
  56. }
  57. cout<<ans<<endl;
  58. }
  59. return 0;
  60. }

HDU-2588-GCD (欧拉函数)的更多相关文章

  1. HDU 2588 GCD (欧拉函数)

    GCD Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status De ...

  2. HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. 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 和 ...

  4. HDU 1695 GCD (欧拉函数,容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  5. hdu 1695 GCD (欧拉函数+容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. hdu 1695 GCD 欧拉函数 + 容斥

    http://acm.hdu.edu.cn/showproblem.php?pid=1695 要求[L1, R1]和[L2, R2]中GCD是K的个数.那么只需要求[L1, R1 / K]  和 [L ...

  7. HDU 1695 GCD 欧拉函数+容斥原理+质因数分解

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:在[a,b]中的x,在[c,d]中的y,求x与y的最大公约数为k的组合有多少.(a=1, a ...

  8. BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】

    2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 4436  Solved: 1957[Submit][Status][Discuss ...

  9. HDU 2824 简单欧拉函数

    1.HDU 2824   The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a ...

  10. POJ 2773 Happy 2006【GCD/欧拉函数】

    根据欧几里德算法,gcd(a,b)=gcd(a+b*t,b) 如果a和b互质,则a+b*t和b也互质,即与a互质的数对a取模具有周期性. 所以只要求出小于n且与n互质的元素即可. #include&l ...

随机推荐

  1. Python 爬虫闯关(第一关)

    在学习爬虫时,遇到了一个有意思的网站,这个网站设置了几个关卡,需要经过爬虫进行闯关,随着关卡的网后,难度不断增加,在闯关的过程中需要学习不同的知识,你的爬虫水平也自然随之提高. 今天我们先来第一关,访 ...

  2. ACM学习历程—HDU 5072 Coprime(容斥原理)

    Description There are n people standing in a line. Each of them has a unique id number. Now the Ragn ...

  3. Django_form补充

    问题1:  注册页面输入为空,报错:keyError:找不到password def clean(self): print("---",self.cleaned_data)     ...

  4. Centos6.5命令行快捷键

    ctrl+a打开一个新的终端 ctrl+l 清除屏幕内容 ctrl+a 切换到命令行开始ctrl+e 切换到命令行末尾ctrl+u 剪切光标之前的内容ctrl+k 剪切光标之后的内容 Ctrl+-&g ...

  5. a标签中href="javacript:;" href="javacript:void(0);" href="#"区别

    在使用<a>标签时,经常会绑定其他事件比如onclick,这时候我们会给<a>标签的href属性赋值为“#”,“javacript:;”,“javacript:void(0); ...

  6. HTML5对表单的约束验证

    在HTML5中增加了许多新的功能,用于表单提交到服务器之前对表单进行数据的验证(抢了javascript的饭碗),有了这些功能,即便是javascript没有加载进来还是可以确保基本的验证.换句话说, ...

  7. 【转】 Pro Android学习笔记(二一):用户界面和控制(9):Gallery和SimpleAdapter

    Gallery画廊式控件,如图所示,但是在API level 16,也即Android 4.1,被deprecated,可以使用HorizontableScroolView和ViewPager.但是后 ...

  8. redis持久化  发布消息与订阅

    vi /usr/local/redis/etc/redis.conf  快照方式:     save 900 1     save 300 10     save 60 10000 aof方式: ap ...

  9. Matlab数据类型的转换

    Matlab中有15种基本数据类型,主要是整型.浮点.逻辑.字符.日期和时间.结构数组.单元格数组以及函数句柄等. 1.整型:(int8:uint8:int16:uint16:int32:uint32 ...

  10. 阿里云OSS安装使用问题

    最近一政府客户需要将系统部署到政务网(阿里云,不能连接外网),需要挂载OSSFS,通过官网文档,基本可以按流程完成安装,但是安装过程中遇到的几个问题需要了解一下. 服务器级OSS信息 系统:CentO ...