hdoj 2588GCD(欧拉函数)
来源:互联网 发布:存储卡数据修复 编辑:程序博客网 时间:2024/05/29 21:29
GCD
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1217 Accepted Submission(s): 551
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.
(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
31 110 210000 72
Sample Output
16260
分析:假设x<=n,n=p*d,x=q*d.假设n与x的最大公约数为d,则能够推出p与q肯定是互质的,因为x<=n所以要求的就是p的欧拉函数值了,那么我们就转化成求满足:n=p*d,并且d>=m的p的欧拉函数值之和。
<span style="font-size:18px;">#include<cstdio>#include<cstring> #include<cmath>#include<cstdlib>#include<algorithm>using namespace std;int Euler(int n){ int ret=n,i; for(i=2;i<=sqrt(n);i++) if(n%i==0) { ret=ret/i*(i-1); while(n%i==0) n=n/i; } if(n>1) ret=ret/n*(n-1); return ret;}int main(){ int t; scanf("%d",&t); while(t--) { int n,m,i; scanf("%d%d",&n,&m); __int64 sum=0; for(i=1;i<=sqrt(n);i++) if(n%i==0) { if(i>=m) sum+=Euler(n/i); if(i*i!=n&&n/i>=m)//1.i*i!=n是判断前面是否加过 2.注意这儿的n/i>=m不能丢 sum+=Euler(i); } printf("%I64d\n",sum); } return 0;}</span>
0 0
- 【欧拉函数】 HDOJ 2588 GCD
- hdoj 2588 GCD(欧拉函数)
- hdoj 2588GCD(欧拉函数)
- HDOJ GCD 2588【欧拉函数】
- HDOJ 2588 GCD(欧拉函数)
- hdoj 2588 GCD【欧拉函数】
- HDOJ 2588 GCD (欧拉函数)
- hdoj GCD 2588 (欧拉函数)
- HDOJ 题目2588 GCD(欧拉函数)
- hdoj 2588 GCD 【欧拉函数 问题转换】
- HDOJ GCD Again 1787【欧拉函数】
- HDOJ-1787 GCD Again(欧拉函数)
- HDU/HDOJ 1695 GCD 欧拉函数+容斥原理
- 【容斥原理+欧拉函数】 HDOJ 1695 GCD
- 【欧拉函数】 HDOJ 4983 Goffi and GCD
- hdoj 1787 GCD Again(欧拉函数)
- HDOJ 题目1787 GCD Again(欧拉函数)
- HDOJ 1787 GCD Again(欧拉函数)
- 开发团队的效率
- hdfs shell命令记录
- Android Recycler View Header Footer 下拉刷新,自动加载更多,空view,loading view
- Code Forces 538 A. Cutting Banner(水~)
- Java 中常用缓存Cache机制的实现
- hdoj 2588GCD(欧拉函数)
- 类型转换(C*)pB
- 那不勒斯中文离线地图App上线
- 抽象工厂模式
- 一个HashMap和TreeSet综合使用的小例子
- 操作mysql的笔记
- 噩梦射手5 移动 转向 这个没有加速的过程 不适合rpg人物 把移动检测去掉
- 关于函数指针
- 手机安全卫士------手机防盗页面之sim卡绑定&读取联系人