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. Django--form生成select标签

    需求 Django--form表单中的select生成方法,如果select中的选项不固定,需要怎么操作. 速查 1.固定select选项 forms 1 2 3 class 表单类名称(forms. ...

  2. Python基础入门-IF语句

    今天给大家分享一下Python中的IF语句的使用场景以及注意事项.主要内容如下: 1.python中的真假 2.Python操作符 3.if语句实例和嵌套实例 4.if语句中的if嵌套实例 5.and ...

  3. 什么是Condition Number(条件数)?

    In the field of numerical analysis, the condition number of a function with respect to an argument m ...

  4. MySQL性能调优与架构设计——第4章 MySQL安全管理

    第4章 MySQL安全管理 前言 对于任何一个企业来说,其数据库系统中所保存数据的安全性无疑是非常重要的,尤其是公司的有些商业数据,可能数据就是公司的根本,失去了数据的安全性,可能就是失去了公司的一切 ...

  5. 【Android学习】Android编码规范

    四种常见的命名法 比较Java和c#的命名规范的不同点 常量用大写 java方法首字母不大写,应该小写 函数行数限制 不要用拼音 参照物,Android源码 看源码工具,SourceInsight 和 ...

  6. .net List<T>

    List的几个方法 List=>List.Find()List.FindAll()List.Contains() List.ForEach()List.ConvertAll() 1. 先比较Fi ...

  7. 1、认识Socket

    专业术语定义:(不易理解浏览大体意思即可) 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket. 建立网络通信连接至少要一对端口号(socket).socket本 ...

  8. kali linux之sqlmap

    一款开源的命令行自动SQL注入工具,它能够对多种主流数据库进行扫描支持,基于Python环境. 检测动态页面中get/post参数,cookie,http头 数据榨取/文件系统访问 操作系统命令执行 ...

  9. leecode刷题(3)-- 旋转数组

    leecode刷题(3)-- 旋转数组 旋转数组 给定一个数组,将数组中的元素向右移动 K 个位置,其中 K 是非负数. 示例: 输入: [1,2,3,4,5,6,7] 和 k = 3 输出: [5, ...

  10. luoguP4234 最小差值生成树

    https://www.luogu.org/problemnew/show/P4234 按照边的权值从小到大排序,依次加入,并删除能够删除的权值最小的一条边,用 set 维护当前所有边的边权,并查集维 ...