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.

InputThe 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.OutputFor 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(范围2~1e8),求在小于等于n的数中,有多少数满足gcd(i,n)>=m;
思路:很明显是一个欧拉函数,但是它的gcd不是一是m,因此我们要把它化为m,gcd为一,乘上m,gcd不就是m了吗
因此,我们要找n所有因子,
  1. 当因子p大于等于m的时, n = p *n/p,这个时候只要知道n/p的欧拉值就可以了euler(n/p),表示的gcd为一,*p,gcd就是p>=m;
  2. 当因子p,有n/p>=m时,并且保证 n/p !=p,这个时候只要知道p的欧拉值就可以了euler(p),表示的gcd为一,*n/p,gcd就是n/p>=m;
  3. 两者之间是没有重复的,唯一存在可能重复的就是当n/p=p的时候,特判一下就可以了euler(p),and euler(n/p) 会有重复的部分,但他们的乘项不同,乘出的结果也就不同
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#define Mod 1000000007
using namespace std;
typedef long long ll;
const ll N = +;
map<ll,ll> elh;
long long a,b;
ll sum [N];
ll Euler(ll n)
{
if(n==)return ;
ll res =n;
for(ll i=;i<=n/i;i++)
{
if(n%i==)
{
res = res -res/i;
}
while(n%i==)n/=i;
}
if(n>)res -= res/n;
return res;
}
int main()
{
int t;
cin >>t;
while(t--)
{
scanf("%lld%lld",&a,&b);
ll sum =;
for(int i=;i<=a/i;i++)
{
if(a%i==)
{
if(i>=b)
{
sum +=Euler(a/i);
}
if(a/i>=b&&a/i!=i)
{
sum+=Euler(i);
}
}
}
cout <<sum<<endl;
}
return ;
}

不管前方的路有多么曲折,我都会告诉自己,自己的选择,没有后悔,后退的可能,因为热爱所以坚持,既然已经走上这条路,就走出一点风采!!!

E - GCD HDU - 2588的更多相关文章

  1. GCD HDU - 2588

    输入 N 和 M (2<=N<=1000000000, 1<=M<=N), 找出所有满足1<=X<=N 且 gcd(X,N)>=M 的 X 的数量. Inpu ...

  2. D - GCD HDU - 1695 -模板-莫比乌斯容斥

    D - GCD HDU - 1695 思路: 都 除以 k 后转化为  1-b/k    1-d/k中找互质的对数,但是需要去重一下  (x,y)  (y,x) 这种情况. 这种情况出现 x  ,y ...

  3. HDU 2588 思维 容斥

    求满足$1<=X<=N ,(X,N)>=M$的个数,其中$N, M (2<=N<=1000000000, 1<=M<=N)$. 首先,假定$(x, n)=m$ ...

  4. HDU 2588 GCD 【Euler + 暴力技巧】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=2588 GCD Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  5. HDU 2588 GCD (欧拉函数)

    GCD Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status De ...

  6. HDU 2588 GCD

    题目大意:给定N,M, 求1<=X<=N 且gcd(X,N)>=M的个数. 题解:首先,我们求出数字N的约数,保存在约数表中,然后,对于大于等于M的约数p[i],求出Euler(n/ ...

  7. HDU 2588 GCD(欧拉函数)

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

  8. HDU 2588 GCD &amp;&amp; GCD问题总结

    GCD(一) 题目: The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written ( ...

  9. 题解报告:hdu 2588 GCD(欧拉函数)

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

随机推荐

  1. DOS & UNIX文件格式转换

    1.使用vi编辑器 vi xxxx :set fileformat=unix(or dos) :wq 2.使用 dos2unix 这个只能把DOS转换成UNIX文件 . sudo apt-get in ...

  2. C#使用CUDA

    随着信息处理的爆炸增长,传统使用CPU计算已经无法满足计算作业增长的需求,GPU的出现为批量作业提供了新的契机.GPU计算拥有很类库,比如CUDA.OpenCL等,但是可以发现CUDA是其中相对比较成 ...

  3. DRF-路由

    路由Routers 对于视图集ViewSet,我们除了可以自己手动指明请求方式与动作action之间的对应关系外,还可以使用Routers来帮助我们快速实现路由信息. REST framework提供 ...

  4. Introduction - Welcome

    摘要: 本文是吴恩达 (Andrew Ng)老师<机器学习>课程,第一章<绪论:初识机器学习>中第1课时<欢迎参加机器学习课程>的视频原文字幕.为本人在视频学习过程 ...

  5. find the mincost route【无向图最小环】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1599 Problem Description 杭州有N个景区,景区之间有一些双向的路来连接,现在860 ...

  6. 学习笔记:CentOS7学习之二十一: 条件测试语句和if流程控制语句的使用

    目录 学习笔记:CentOS7学习之二十一: 条件测试语句和if流程控制语句的使用 21.1 read命令键盘读取变量的值 21.1.1 read常用见用法及参数 21.2 流程控制语句if 21.2 ...

  7. c# 所有类型都是从object继承,那么值类型默认也有装箱吗?

    我们知道,c#所有类型都是从System.Object继承,int等值类型也逃脱不了这种命运,那难道值类型默认有装箱操作吗?答案是否,在CLR via这本书中有简短的解释说明: 1.值类型从Syste ...

  8. centos7ping www.baidu.com没有ping通

    在linux中ping www.baidu.com 无法ping通,可能原因是DNS没配置好 1.修改vi /etc/resolv.conf 增加如下内容: nameserver 114.114.11 ...

  9. java版MD5签名工具类

    package com.net.util; import java.security.MessageDigest; /** * MD5签名工具类 * @author zhangdi * */ publ ...

  10. SVN常用命令--Mac端【转载】

    * 版本库布局 1. trunk主干 trunk就是开发的主线,一般项目都是导入到主线来开发的. 2. branches分支 branches一般是trunk某个版本的拷贝,如果你想在某一段时间单独对 ...