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. oracle导库

    cmd窗口直接输入导库命令即可,不需要进入sqlplus C:\Documents and Settings\Administrator> imp username/pass@orcl file ...

  2. java匿名内部类举例

    public class Test { public static void main(String[] args) { //4.匿名内部类 //主要是针对那些不能直接创建对象的抽象类和接口而来的 S ...

  3. Grails笔记二:grails 2.4.3版本下generate-*失效问题解析

    最近在学grails框架,因为其敏捷性让我非常喜欢,不过有点让人恼怒的是也许因为grails框架太新了,所以关于grails的书籍很少,而且市面上的书籍大部分都是2007或者2009年的,官方文档又都 ...

  4. 关于破解Quartus

    在网上找了很多资料,说的也很详细,安装的Quartus13.0,在破解的时候遇到x64和x86两种破解器,两个针对的路径不一样,如果搞混了~可能就会出现这种情况   Error: Current li ...

  5. 解决MVC模式文件下载附件中文名称乱码

    解决如下: 进行url编码:Server.UrlPathEncode(file.AttachmentName) return File(file.TempWorkPath, CommonTools.G ...

  6. Excel表单的读取与处理 PHPExcel与Apache POI

    近日,连续遇到需要对Excel表单内容进行读取的需求.一个是在php环境下,一个是在java环境下.这里简要记录这两种环境,利用第三方提供的函数库对Excel进行处理的方法. d0710 : Fini ...

  7. unity3d 初学者遇到的坑(提醒自己不要范同样的错误)

    使用NGUI的过程中,总是会发生一些就像我这样的初学者遇到的坑:一直以为在创建  一直以为图中的文字Depth深度大于beijingheitu的深度,会显示在beijingheitu下所有子物体之上, ...

  8. 【Alpha】第三次Daily Scrum Meeting

    GIT 一.今日站立式会议照片 二.会议内容 1.确定开发人员负责开发模块 开发人员 开发模块 杨嘉成 注册登陆模块 吴文庆 服务模块 程志铭 个人中心 2.测试人员在开发人员完成该模块后紧跟测试 三 ...

  9. 201521123072《Java程序设计》第6周学习总结

    201521123072<Java程序设计>第6周学习总结 标签(空格分隔): java 1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画 ...

  10. 《Java程序设计》第5周学习总结

    1. 本章学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 1.2 可选:使用常规方法总结其他上课内容. 2. 书面作业 1. 代码阅读:Child压缩包内源代码 1.1 com.par ...