GCD

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

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
 
 
 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h> using namespace std;
int fun(int n)//传入一数,返回此数的欧拉函数,用素数表会更快
{
int sum=n;
int i;
for(i=; i*i<=n; i++)
{
if(n%i==)
{
sum=sum/i*(i-);
while(n%i==)n/=i;
}
}
if(n!=)
{
sum=sum/n*(n-);
}
return sum;
} int main()
{
int t,i,n,m,ans,size;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
ans=;
size=sqrt(n+0.5);
for(i=; i<=size; i++)
{
if(n%i==)
{
if(i>=m)
ans+=fun(n/i);
if(i!=n/i&&n/i>=m)ans+=fun(i);
}
}
printf("%d\n",ans);
}
}
 
Source

GCD hdu2588的更多相关文章

  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. 【hdu-2588】GCD(容斥定理+欧拉函数+GCD()原理)

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

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

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

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

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

  7. hdu2588 GCD

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

  8. 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 ...

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

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

随机推荐

  1. python 之 计数器(counter)

    Counter是对字典类型的补充,用于追踪值的出现次数. ps:具备字典的所有功能 + 自己的功能 c = Counter('abcdeabcdabcaba') print c 输出:Counter( ...

  2. Amazon Aurora解读(SIGMOD 2017)

    Amazon在SIGMOD 2017发表了论文<Amazon Aurora: DesignConsiderations for High Throughput Cloud-Native Rela ...

  3. solr-geohsah 按照距离搜索分组

    通过solr的domain-import,将mysql的数据通过查询,导入到solr中.java通过使用solrj,链接solr,调用domaininport,并将分页参数设置到domain-impo ...

  4. Statement和PrepareStatement区别

    网上很多都说区别是PrepareStatement可以批处理.实际上二者都是可以进行批处理的. 区别在于: 1.PrepareStatement要求预编译的sql必须是格式固定,使用占位符获取参数. ...

  5. MongoDB聚合

    --------------------MongoDB聚合-------------------- 1.aggregate():     1.概念:         1.简介             ...

  6. 关于 ThinkPHP 在 Nginx 服务器上 使用U方法跳转问题

    这个问题已多次遇到,关于tp 框架 使用U 方法跳转, 在Nginx 服务器上可能会遇到路由跳转不过去前面带点(如:./xx) 解决这个问题,可以在tp的入口文件 index.php 里定义个常量 d ...

  7. Java基础精选,你答对了几道?

    没有技术深度是大多程序员的一种常态. 但是当你成为一个资深的工程师的时候,很多公司并不希望你还是那样平庸,没有深度.虽然你会纳闷,我就算有深度你们也不一定用得上呀?然而到了这个级别的人需求量并不像初中 ...

  8. javascript学习笔记-3

    1.对于javascript中的this关键字,表示的是当前代码所处的对象. var a={ get:function(){ this.val=12 } } console.log(a.val); a ...

  9. 微软微服务eShopOnContainers示例之EventBusRabbitMq解析与实践

    eShopOnContainers eShopOnContainers是微软官方的微服务架构示例,GitHub地址https://github.com/dotnet-architecture/eSho ...

  10. 第1阶段——uboot分析之通过nand命令读内核(8)

    本节主要学习: 详细分析UBOOT中"bootcmd=nand read.jffs2 0x30007FC0 kernel;bootm 0x30007FC0" 怎么实现nand命令读 ...