GCD nyoj1007(欧拉函数运用&&数论入门)
来源:互联网 发布:vmware10 for mac下载 编辑:程序博客网 时间:2024/05/17 02:32
GCD
时间限制:1000 ms | 内存限制:65535 KB
难度:3
- 描述
- 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,please answer sum of X satisfies 1<=X<=N and (X,N)>=M.- 输入
- 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 (1<=N<=10^9, 1<=M<=10^9), representing a test case.
- 输出
- Output the answer mod 1000000007
- 样例输入
31 110 210000 72
- 样例输出
1351305000
- 上传者
- ACM_张书军题意:Given integers N and M,please answer sum of X satisfies 1<=X<=N and (X,N)>=M./*就在这一句了*/给你两个数 N M 求1~N 之间所有gcdx的和
/*在数论,对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目。*//*思路:枚举n的因子。假设n的因子为d。d*gcd(x/d,n/d)=1。d*Euler(n/d)就是因子为gcd(x,n)=d,从而求gcd(x,n)的和。*/#include<stdio.h>#include<string.h>#include<iostream>using namespace std;const int mod=1000000007;long long Euler(long long n)//欧拉函数{ long long c=n,i; for(i=2; i*i<=n; i++) { if(n%i==0) { while(n%i==0) n/=i; c=c/i*(i-1);//φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn); } } if(n!=1) c=c/n*(n-1); return c;}//求 x和long long Euler_sum(long long n){ if(n==1) return 1; else return n*Euler(n)/2;}int main(){ long long a,b; int t; cin>>t; while(t--) { while(cin>>a>>b) { int cnt; long long i,c=0; for(i=1; i*i<=a; i++) { if(a%i==0) { if(i>=b) { cnt=i;//- - c=(c+cnt*Euler_sum(a/cnt))%mod; } if(i*i!=a&&a/i>=b)//枚举i与n的因子。 { cnt=a/i; c=(c+cnt*Euler_sum(a/cnt))%mod; } } } cout<<c<<endl; } }}
0 0
- GCD nyoj1007(欧拉函数运用&&数论入门)
- Sum nyoj 欧拉定理简单运用(数论入门)
- HDU1695-GCD(数论-欧拉函数-容斥)
- uva 11424 && 11426 GCD - Extreme(数论:欧拉函数)
- (hdu 2588 gcd)<数论—欧拉函数>
- hdu1787 GCD Again(数论:欧拉函数)
- hdu 2588 GCD [欧拉函数]【数论】*
- HDU 2588 GCD [欧拉函数]【数论】
- HDU5514 Frogs(GCD+欧拉函数+数论)
- BZOJ_P2818 GCD(数论GCD+欧拉函数线性筛)
- NYOJ1007---GCD
- BZOJ 2818 Gcd (数论 欧拉)
- hdu 1787 GCD Again 欧拉函数小水水 数论
- FZU 1969数论 GCD+欧拉函数应用
- UVA 11426 GCD - Extreme (II) (数论|欧拉函数)
- HDU-4983-Goffi and GCD【数论】【欧拉函数】
- 欧拉函数(数论)
- HDU 1695 GCD (数论-整数和素数,欧拉函数,组合数学-容斥原理)
- DirectX 11游戏编程学习笔记之5: 第4章Direct3D Initialization(Direct3D初始化)
- POJ 2923 - Relocation(状态压缩+01背包)
- Cocos2d-x中Vector<T>容器以及实例介绍
- 第39届ACM亚洲区域赛牡丹江赛区赛后总结
- depcomp: line 571: exec: g++: not found
- GCD nyoj1007(欧拉函数运用&&数论入门)
- 解决ThinkPHP中开启调试模式无法加载模块的问题。
- SQL优化相关--转载
- matlab灰度共生矩阵提取纹理特征
- 好科技好技术
- 方格取数
- Cocos2d-x中Socket的简单使用
- Java并发框架——AQS之如何使用AQS构建同步器
- POJ 1890 - A Simple Problem with Integers (线段树 Splay)