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. 【从零开始搭建K8S】【第一篇】CentOS7.6离线安装Docker(手动安装以及基于yum本地源安装)

    下载CentOS7.6以及最小化安装CentOS7.6版本.由于CentOS属于开源软件,在国内也有很多的mirror站点可供下载,我选择的是华为站点进行下载:http://mirrors.huawe ...

  2. ip routing 开启三层路由模式

    no ip router是关闭路由协议,no ip routing 是关闭三层的路由工作模式 no ip route是删除某条(静态)路由,比如no ip router 0.0.0.0 0.0.0.0 ...

  3. 源码搭建zabbix服务

    1) 部署LNMP 1.1) cd /root tar -xf lnmp_soft.tar.gz cd lnmp_soft/ tar -xf nginx-1.10.3.tar.gz cd nginx- ...

  4. SQL注入(字符型)

       靶场:sqli-labs @SQLi最重要的一点:别上来就对着输入框注入,完整语句写出来,始终在语句中写完整的,最后把完整的一部分截取出来作为输入 @URL编码:为避免歧义,URL中,如 %2b ...

  5. Linux特基础的知识(接上一条)

    grep:文本过滤工具(找到要找的文本) print lines matching a pattern例: 打印 行 匹配 一个 模式/样式[root@oldboyedu /opt]# grep &q ...

  6. MongoTemplate 使用 _id 查询

    MongoTemplate mt; DBObject lisi = new BasicDBObject(); lisi.put("_id", new BasicDBObject(& ...

  7. 【VS开发】VC下加载JPG/GIF/PNG图片的两种方法

    1.用API OleLoadPicture来加载JPG.GIF格式的图片(注:不支持PNG格式,另外GIF只能加载第一帧,且不支持透明) OleLoadPicture 函数实际上创建了一个IPictu ...

  8. Java学习笔记-Java概述和环境配置

    基础常识 软件:一系列按照特定顺序组织的计算机数据 和指令的集合 常见的软件: 系统软件:如:DOS,windows,Linux等 应用软件:如:扫雷,迅雷,QQ等 软件的出现实现了人与计算机之间的更 ...

  9. 理解clientX、clientY、offsetLeft、event.offsetTop、offsetWidth、offsetHeight、clientWidth、clientHeight、scrollTop、scrollHeight

    一.clientX和clientY 事件发生时,鼠标距离浏览器的可视区域的X.Y轴的位置,不包含滚动条的区域的部分.就算是页面进行了滚动,鼠标的坐标值还是参考可视区域的. 二.offsetLeft和o ...

  10. vim版本更新

    版本问题 ubuntu 14.05 安装完YouCompleteMe后不生效,提示:YouCompleteMe unavailable : requires Vim 7.4.143经过检索与查询,ub ...