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<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm> using namespace std;
long long int oula(int n)
{
long long int res=1;
for(int t=2;t*t<=n;t++)
{
if(n%t==0)
{
n/=t;
res*=t-1;
while(n%t==0)
{
n/=t;
res*=t;
}
} }
if(n>1)
{
res*=n-1;
}
return res;
} int main()
{
int n;
cin>>n;
int a,b;
long long int ans;
for(int t=0;t<n;t++)
{
ans=0;
scanf("%d%d",&a,&b);
int j;
for( j=1;j*j<a;j++)
{
if(a%j==0)
{ if(j>=b)
{
ans+=oula(a/j);
}
if(a/j>=b)
{
ans+=oula(j);
}
}
}
if(j*j==a&&j>=b)
{
ans+=oula(j);
}
cout<<ans<<endl;
} return 0;
}

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. ACM学习历程—HDU5476 Explore Track of Point(平面几何)(2015上海网赛09题)

    Problem Description In Geometry, the problem of track is very interesting. Because in some cases, th ...

  2. MySQL读取各个my.cnf配置文件的先后顺序是:

    /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 其他自定义路径下的my.cnf,例如:/data/mysql/y ...

  3. SQL Server:sp_send_dbmail参数设置

    sp_send_dbmail [ [ @profile_name = ] 'profile_name' ]    [ , [ @recipients = ] 'recipients [ ; n ]'  ...

  4. Otter入门简介

    一.Otter简介 1.1  otter是什么? otter 译意: 水獭,数据搬运工 语言: 纯java开发 定位: 基于数据库增量日志解析,准实时同步到本机房或异地机房的mysql/oracle数 ...

  5. Ok6410裸机驱动学习(二)ARM基础知识

    1.ARM工作模式 ARM微处理器支持7种工作模式,分别为: l  用户模式(usr):ARM处理器正常的程序执行状态(Linux用户态程序) l  快速中断模式(fiq):用于高速数据传输或通道处理 ...

  6. JAVA基础知识总结2(语法基础)

    关键字:其实就是某种语言赋予了特殊含义的单词. 保留字:暂时还未规定为关键字的单词,保留准备日后要使用的单词. 标识符:开发人员程序中自定义名词,比如类名,变量名,函数名. PS:1.不能使用关键字. ...

  7. 菜鸟攻城狮2(JAVA开发环境)

    1.JDK下载路径:www.oracle.com/technetwork/java/javase/downloads 2.安装案例:最后一步认证操作 win+R 或者 点击开始--〉运行 输入“cmd ...

  8. PHP和MySql数据库,如何获取每个分类的记录的总数

    示例的数据库,如下: 本文说的问题,就是统计每个学院(Sdept)的人数. 还有很多情况,比如说:在制作CMS的时候,文章有个分类问题,所有的文章的记录都是存放到同一个表中. 当我们需要统计每个分类的 ...

  9. macos上改变输入法顺序

    设置界面上是不能拖放顺序的,唯一解决办法是: 一.先选择所有文档使用相同输入源 二.选择用美国英语 三.再选择允许多个输入源,再打开原来的中文输入法 顺序就调过来了!尼玛,这就是苹果的人性化?懒得吐嘈 ...

  10. Luogu 2839 [国家集训队]middle

    感觉这题挺好的. 首先对于中位数最大有一个很经典的处理方法就是二分,每次二分一个数组中的下标$mid$,然后我们把$mid$代回到原来的数组中检查,如果一个数$a_{i} \geq mid$,那么就把 ...