GCD

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 812    Accepted Submission(s): 363

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
 /*
题意:求1<=X<=N 满足GCD(X,N)>=M. 思路:if(n%p==0 && p>=m) 那么gcd(n,p)=p,
求所有的满足与n的最大公约数是p的个数,
就是n/p的欧拉值。
因为与n/p互素的值x1,x2,x3....
满足 gcd(n,x1*p)=gcd(n,x2*p)=gcd(n,x3*p).... 枚举所有的即可。
*/ #include<stdio.h>
#include<stdlib.h>
#include<string.h> int Euler(int n)
{
int i,temp=n;
for(i=;i*i<=n;i++)
{
if(n%i==)
{
while(n%i==)
n=n/i;
temp=temp/i*(i-);
}
}
if(n!=)
temp=temp/n*(n-);
return temp;
} void make_ini(int n,int m)
{
int i,sum=;
for(i=;i*i<=n;i++)//!!
{
if(n%i==)
{
if(i>=m)
sum=sum+Euler(n/i);
if((n/i)!=i && (n/i)>=m)//!!
sum=sum+Euler(i);
}
}
printf("%d\n",sum);
} int main()
{
int T,n,m;
while(scanf("%d",&T)>)
{
while(T--)
{
scanf("%d%d",&n,&m);
make_ini(n,m);
}
}
return ;
}

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. GCD - Extreme(欧拉函数变形)

    题目链接:https://vjudge.net/problem/UVA-11426 题目大意: 给出整数n∈[2,4000000],求解∑gcd(i,j),其中(i,j)满足1≤i<j≤n. 的 ...

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

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

  10. HDU 2824 简单欧拉函数

    1.HDU 2824   The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a ...

随机推荐

  1. C++实现文件自校验的一种方法

    #include <iostream> #include <stdio.h> extern long FileSizeof(char *); int main() { if(F ...

  2. 学习 swift (1)

    https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwi ...

  3. 网络编程——http协议

    1.TCP/IP 基本知识 一.概念 TCP/IP协议是一个协议的集合,它是由众多的互联网相关联的协议集合的总称.如图 二.TCP/IP分层管理 TCP/IP模型分为5层:应用层,传输层,网络层,数据 ...

  4. 找到SVN版本机上项目的地址

    在你的项目文件上右击:点击Copy URL to Clipboard(复制URL到剪切板)

  5. Vue 部署单页应用,刷新页面 404/502 报错

    在 Vue 项目中,可以选择 hash或者 history.pushState() 实现路由跳转.如果在路由中使用history模式: export default new Router({ mode ...

  6. VUE 项目刷新路由指向index.html

    背景描述: VUE 项目经过 npm run bulid 生成静态文件上传到服务器后,当我们切换路由并刷新页面,nginx 服务器会报 502 或者 404 错误. 原因分析: 我猜测是因为在 VUE ...

  7. Windows下安装MySQL详细教程

    Windows下安装MySQL详细教程 1.安装包下载  2.安装教程 (1)配置环境变量 (2)生成data文件 (3)安装MySQL (4)启动服务 (5)登录MySQL (6)查询用户密码 (7 ...

  8. Python小白学习之路(十七)—【内置函数二】

    序列操作类函数 all() 功能:判断可迭代对象的每个元素是否都为True值注意:If the iterable is empty, return True.(举例3) 回顾:None     ''  ...

  9. 使用命令行创建一个vue项目的全部命令及结果

    dell@DESKTOP-KD0EJ4H MINGW64 /f/05 项目 $ npm install --global vue-cli npm WARN deprecated coffee-scri ...

  10. POJ 1083

    #include<iostream> #include<stdio.h> #include<algorithm> #define MAXN 400 using na ...