南邮 OJ 1126 GCD
来源:互联网 发布:少见的姓氏 知乎 编辑:程序博客网 时间:2024/05/29 05:57
GCD
时间限制(普通/Java) : 2000 MS/ 6000 MS 运行内存限制 : 65536 KByte
总提交 : 141 测试通过 : 23
总提交 : 141 测试通过 : 23
比赛描述
The greatest common divisor GCD(a,b) of two positive integer a and b,sometimes written (a,b),
is the largest divisior 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 difficlut problem.
Given integer N and M,how many integer X satisfies 1<=X<=N and (X,N)≥M.
is the largest divisior 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 difficlut problem.
Given integer N and M,how many integer X satisfies 1<=X<=N and (X,N)≥M.
输入
The first line or input is an integer T(<=3000)representing the number of test cases.The following T lines each contains two numbers N and M(1<=N<=1000000000,0<=M<=1000000000),representing a test case.
输出
For each test case,output the answer on a single line.
样例输入
3
1 1
10 2
10000 72
样例输出
1
6
260
题目来源
第九届中山大学程序设计竞赛预选题
/* 题意:求有多少x(1<=x<=n),使得gcd(x,n)>=m; 先求n的所有大于等于m的因子,ei 答案ans=∑phi[n/ei];phi[i]为欧拉函数,为不大于i且与i互质的正整数个数 why? 对于一个与ei互质且小于等于n/ei的正整数p来说,p*ei<=n,gcd(p*ei,n)=ei;则phi[n/ei]就是1~n中的与n最大公约数是ei的个数。而n与1~n的最大公约数必定是n的因子。所以符合gcd(x,n)>=m的x为n所有大于等于m因子的倍数,用phi即可避免重复。*/#include <cstdio>#include <cstring>#include <cmath>#include <queue>#include <iostream>#include <algorithm>using namespace std;const int maxn=1000;int e[maxn];int euler_phi(int n){ int m=(int)sqrt(n+0.5); int ans=n,i; for(i=2;i<=m;i++) { if(n%i==0) { ans=ans/i*(i-1); while(n%i==0)n/=i; } } if(n>1)ans=ans/n*(n-1); return ans;}int main(){ int T,n,m; cin>>T; while(T--) { cin>>n>>m; int i,j,k,t=0,num,ans=0; num=(int)sqrt(n+0.5); for(i=1;i<num;i++) { if(n%i==0) { if(i>=m)e[t++]=n/i; if(n/i>=m)e[t++]=i; } } if(num*num==n&&num>=m)e[t++]=num; for(i=0;i<t;i++) ans+=euler_phi(e[i]); cout<<ans<<endl; } return 0;}
0 0
- 南邮 OJ 1126 GCD
- UVa OJ 11417-GCD
- 新视野OJ 2818: Gcd
- ACdream OJ 1153 (k-GCD)
- 【杭电oj】2504 - 又见GCD(GCD)
- AOJ-AHU-OJ-401 Fibonacci & GCD
- 九度OJ 1056:最大公约数 (GCD)
- 杭电-oj】-2504-又见GCD
- Light OJ -1161 Extreme GCD (容斥)
- BZ OJ 2818 Gcd (欧拉函数)
- 学院OJ 1832: GCD(k, n)>=m
- 新视野OJ 2190 [SDOI2008]仪仗队 (数论-gcd)
- 新视野OJ 2005 [Noi2010]能量采集 (数论-gcd)
- 新视野OJ 2301 [HAOI2011]Problem b (数论-gcd)
- 九度OJ 1336:液晶屏裁剪 (GCD)
- 【杭电oj】1108 - 最小公倍数(gcd,水)
- 【杭电oj】1722 - Cake(数论,GCD)
- 【杭电oj】1787 - GCD Again(欧拉函数)
- 2015年8月3日--oracle
- 配置IIS7运行CGI脚本创建动态网页
- WPF MVVM初体验
- importtsv工具使用笔记
- Runtime获取网络状态
- 南邮 OJ 1126 GCD
- Android Studio系列教程五--Gradle命令详解与导入第三方包
- 06-js禁止回车提交表单
- VS2013编译安装VTK-6.2.0_支持Qt5.4.2
- poj解题报告——2234
- 二三四五六章作业
- 大数模板
- hulu面试经验
- 南邮 OJ 1127 Stick