GCD

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3559    Accepted Submission(s): 1921

Problem Description
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
3
1 1
10 2
10000 72
 
Sample Output
1
6
260
 题意:输入测试样例数 t,输入n ,m。判断满足gcd(x,n)>=m条件x的个数
因为gcd(x,n)>=m
所以可以推出gcd(x/m,n/m)==1
 
所以题目转化为满足gcd(x/m,n/m)==1中X的个数 <==> 求 不大于n/m且与其互质的 n/m的个数 即求ϕ(n/m)

  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6. typedef long long ll;
  7.  
  8. ll euler(ll x)
  9. {
  10. ll res = x;
  11. for(int i= ;i*i<=x ;i++)
  12. {
  13. if(x%i == )
  14. {
  15. res = res/i*(i-);
  16. while(x%i==)
  17. x/=i;
  18. }
  19. }
  20. if(x>)
  21. res = res/x*(x-);
  22. return res;
  23. }
  24.  
  25. int main(){
  26. int T;
  27. scanf("%d",&T);
  28. while(T--)
  29. {
  30. ll n,m;
  31. scanf("%I64d%I64d",&n,&m);
  32. ll ans = ;
  33. for(ll i= ;i*i<=n ;i++)
  34. {
  35. if(n%i == )//i是n的因数
  36. {
  37. if(i >= m)
  38. {
  39. ans += euler(n/i);
  40. }
  41. if((n/i)>=m && n/i != i)//i*(n/i)==n,判断i对应的另一个因数是否符合
  42. {
  43. ans += euler(i);
  44. }
  45. }
  46. }
  47. printf("%I64d\n",ans);
  48. }
  49. return ;
  50. }

hdu2588 GCD的更多相关文章

  1. hdu2588 GCD (欧拉函数)

    GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数.  (文末有题) 知 ...

  2. HDU2588 GCD(欧拉函数)

    题目问[1,n]中与n的gcd大于等于m的数的个数. 好难想... 假设x满足条件,那么gcd(x,n)=d>=m,而x/d与n/d一定互质. 又x<=n,所以x/d<=n/d. 于 ...

  3. hdu2588 gcd 欧拉函数

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

  4. HDU2588:GCD(欧拉函数的应用)

    题目链接:传送门 题目需求:Given integers N and M, how many integer X satisfies 1<=X<=N and (X,N)>=M.(2& ...

  5. 从HDU2588:GCD 到 HDU5514:Frogs (欧拉公式)

    The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the ...

  6. hdu2588 GCD 给定n,m。求x属于[1,n]。有多少个x满足gcd(x,n)>=m; 容斥或者欧拉函数

    GCD Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Sub ...

  7. 【hdu-2588】GCD(容斥定理+欧拉函数+GCD()原理)

    GCD Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissio ...

  8. GCD hdu2588

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

  9. Objective-C三种定时器CADisplayLink / NSTimer / GCD的使用

    OC中的三种定时器:CADisplayLink.NSTimer.GCD 我们先来看看CADiskplayLink, 点进头文件里面看看, 用注释来说明下 @interface CADisplayLin ...

随机推荐

  1. sencha表单入门例子

    来自于<sencha touch 权威指南> ------------------------------- 一.网站结构 二.index.html代码 <!DOCTYPE HTML ...

  2. 25.AVG 函数

    定义和用法 AVG 函数返回数值列的平均值.NULL 值不包括在计算中. SQL AVG() 语法 SELECT AVG(column_name) FROM table_name SQL AVG() ...

  3. Entity Framework 6.0 Tutorials(3):Code-based Configuration

    Code-based Configuration: Entity Framework 6 has introduced code based configuration. Now, you can c ...

  4. SimpleTag——认识自定义标签

    自定义标签 自定义标签的开发与应用步骤 编写完成标签功能的 Java 类(标签处理器) 编写标签库描述(tld)文件,在tld文件中对自定义中进行描述 在 JSP 页面中导入和使用自定义标签 ①. 创 ...

  5. 登录到 SQL Server 实例

    登录到 SQL Server 实例(命令提示符)   登录到 SQL Server 的默认实例 从命令提示符输入以下命令,使用 Windows 身份验证进行连接:     sqlcmd [ /E ] ...

  6. rest 参数和扩展运算符

    rest 参数和扩展运算符 rest 参数的形式为 ...变量名:扩展运算符是三个点 .... rest 参数 function add(...values) { console.log(values ...

  7. (转)Web API 强势入门指南

    原文地址:http://www.cnblogs.com/developersupport/p/aspnet-webapi.html Web API是一个比较宽泛的概念.这里我们提到Web API特指A ...

  8. APUE(3)---文件I/O (1)

    一.引言 UNIX系统中的大多数文件对I/O只需用到5个函数:open/read/write/lseek和close,这些函数都是不带缓冲I/O(Unbuffered I/O).只要涉及到多个进程间共 ...

  9. wpf 依赖属性注册解释

    这个解释的很明白了 http://www.cnblogs.com/xiongpq/archive/2010/06/29/1767905.html

  10. ComicEnhancerPro 系列教程十八:JPG文件长度与质量

    作者:马健邮箱:stronghorse_mj@hotmail.com 主页:http://www.comicer.com/stronghorse/ 发布:2017.07.23 教程十八:JPG文件长度 ...