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
翻译:给出n和m,1<=x<=n,求x符合gcd(x,n)>=m有多少个。
解题过程:
令d=gcd(x,n),显然d是n的因子,并且是x和n的最大公因子,则gcd(x/d,n/d)=1
对于每个d,令y=n/d,找有多少个x/d满足gcd(x/d,y)=1。
欧拉函数登场,累加y的欧拉函数值。
 #include <iostream>
#include<stdio.h>
#include <algorithm>
#include<string.h>
#include<cstring>
#include<math.h>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std; ll euler(ll x)
{
ll res=x;
for(ll i=;i*i<=x;i++)
{
if(x%i==)
{
res=res/i*(i-);
while(x%i==)
x=x/i;
}
}
if(x>)
res=res/x*(x-);
return res;
} int main()
{ ll t,n,m,sum;
scanf("%lld",&t);
while(t--)
{
sum=;
scanf("%lld%lld",&n,&m);
int q=sqrt(n);
ll i;
for(i=;i*i<=n;i++)
{
if(n%i==)
{
if(i>=m)
sum=sum+euler(n/i);
if((n/i)>=m)
sum=sum+euler(i);
}
}
i--;
if(i*i==n && i>=m)
sum=sum-euler(i);
printf("%lld\n",sum);
}
return ;
}
												

hdu2588-GCD-(欧拉函数+分解因子)的更多相关文章

  1. hdu2588 gcd 欧拉函数

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

  2. 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 和 ...

  3. HDU 1695 GCD (欧拉函数,容斥原理)

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

  4. BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】

    2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 4436  Solved: 1957[Submit][Status][Discuss ...

  5. HDU 2588 GCD (欧拉函数)

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

  6. hdu 1695 GCD (欧拉函数+容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  7. 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 ...

  8. Bzoj-2818 Gcd 欧拉函数

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2818 题意:给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x ...

  9. BZOJ2818: Gcd 欧拉函数求前缀和

    给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 如果两个数的x,y最大公约数是z,那么x/z,y/z一定是互质的 然后找到所有的素数,然后用欧拉函数求一 ...

随机推荐

  1. 对KVM虚拟机进行cpu pinning配置的方法

    这篇文章主要介绍了对KVM虚拟机进行cpu pinning配置的方法,通过文中的各种virsh命令可进行操作,需要的朋友可以参考下 首先需求了解基本的信息 1 宿主机CPU特性查看 使用virsh n ...

  2. MySQL完整性约束foreign key与表操作。

    一  MySQL中表的完整性约束: 我们首先知道约束条件跟类型的宽度一样,都是可选的,也就是说,我们在创建表的时候可以不指定,但是为了创建的表更加的完整,我们一般会加一些约束条件,name下面我们讲一 ...

  3. PowerDesigner 概念数据模型(CDM) 说明

        ref: https://blog.csdn.net/tianlesoftware/article/details/6871179 关于PowerDesigner的说明参考: PowerDes ...

  4. python入门-使用API

    python入门-使用API import requests #执行API调用并存储响应 url = 'https://api.github.com/search/repositories?q=lan ...

  5. 23.pyspider安装

    1.pip安装pip3 install pyspider 2.验证安装 pyspider all 3.打开浏览器 输入:127.0.0.1:5000(如下图)

  6. python中的expandtabs、\t

    expandtabs()将tab转换成空格,默认1个tab转成8个空格,\t制表符代表一个tab,我们也可以自定义转换成几个空格 举个例子: 1 a = "hello\tworld" ...

  7. django相关

    后台运行django:https://blog.csdn.net/rnger/article/details/79907884 nohup python manage.py runserver 0.0 ...

  8. 高程三 DOM对象

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  9. Android Netty Client

    Android netty client Start a netty client on android Download netty Download url :https://netty.io/d ...

  10. leetcode1009

    class Solution: def bitwiseComplement(self, N: int) -> int: if N==0: return 1 elif N==1: return 0 ...