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)

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll; ll euler(ll x)
{
ll res = x;
for(int i= ;i*i<=x ;i++)
{
if(x%i == )
{
res = res/i*(i-);
while(x%i==)
x/=i;
}
}
if(x>)
res = res/x*(x-);
return res;
} int main(){
int T;
scanf("%d",&T);
while(T--)
{
ll n,m;
scanf("%I64d%I64d",&n,&m);
ll ans = ;
for(ll i= ;i*i<=n ;i++)
{
if(n%i == )//i是n的因数
{
if(i >= m)
{
ans += euler(n/i);
}
if((n/i)>=m && n/i != i)//i*(n/i)==n,判断i对应的另一个因数是否符合
{
ans += euler(i);
}
}
}
printf("%I64d\n",ans);
}
return ;
}

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. aspx页面上输出xml的问题

    在aspx页面上输出xml,需要在后台输出编码格式和编码类型,如下代码: Response.Charset = "utf-8";//格式Response.ContentType = ...

  2. Part5核心初始化_lesson1---异常向量表

    1.1异常 异常向量: 异常向量表: 代码的编写 start.S文件 gboot.lds链接器脚本文件 makefile工程文件:

  3. Entity Framework 6.0 Tutorials(6):Transaction support

    Transaction support: Entity Framework by default wraps Insert, Update or Delete operation in a trans ...

  4. SpringMVC——映射请求参数

    Spring MVC 通过分析处理方法的签名,将 HTTP 请求信息绑定到处理方法的相应人参中. @PathVariable @RequestParam @RequestHeader 等) Sprin ...

  5. 当this指针成为指向之类的基类指针时,也能形成多态

    this指针: 1)对象中没有函数,只有成员变量 2)对象调用函数,通过this指针告诉函数是哪个对象自己谁. #include<iostream> using namespace std ...

  6. [GO]随机生成切片元素并使用冒泡排序方式进行排序

    package main import ( "math/rand" "time" "fmt" ) func ButtleData(s []i ...

  7. Python - selenium_WebDriver 页面元素操作

    代码是自己写了 python WebDriver  页面操作的常用方法. from selenium import webdriver import time driver = webdriver.F ...

  8. vi常用快捷键汇总

      第一部分:光标移动.复制粘贴.查找替换 [Ctrl] + [f]  下一页 [Ctrl] + [b]  上一页  0或[home]  到行首 $或[end]  到行尾  G  到最后一行  gg ...

  9. Python中多使用迭代器

    英文原文出处:Use More Iterators 本文介绍将代码转换为使用迭代器的原因和实用技巧. 我最喜欢的Python语言的特色之一是生成器,它们是非常有用的,然而当阅读开源代码时,我很少遇到它 ...

  10. GCC 显示所有的warning option

    此事需求的来源是有要求调查,gcc中的那些warning是有问题的,代码必须要修改,那些事需要确认的,就要显示所有的warning选项是什么 查了下,方法如下 显示所有的warning和warning ...