POJ 2480 : Longge\'s problem - gcd之和
来源:互联网 发布:义乌淘宝网店摄影培训 编辑:程序博客网 时间:2024/06/07 09:04
题意:
给出正整数n,计算所有gcd(i,n) (1<=i<=n) 的和。
分析:
在数论中的积性函数概念:对于正整数n的一个算术函数 f(n),若f(1)=1,且当a,b互质时f(ab)=f(a)f(b),在数论上就称它为积性函数。若对于某积性函数 f(n) ,就算a, b不互质,也有f(ab)=f(a)f(b),则称它为完全积性的。
gcd(i,m*n)=gcd(i,m) * gcd(i,n),m,n互质,故gcd是乘性函数。乘性函数的和也是乘性函数。
令所求为f(n),则f(n)=sum(p * phi(n/p)).其中,p是n的因子。则 f(p^r)=r * (p^r - p^(r-1)) + p^r——(#)
将n进行素因子分解,n=p1^k1 * p2^k2 * ... * pm^km.用乘性函数性质解决f(n)=f(p1^k1) * f(p2^k2) * ... * f(pm^km).再套用(#).
#include<iostream>#include<cstdio>#include<cstdlib>#define LL long longusing namespace std;int main(){LL s,n,i;while(~scanf("%lld",&n)){s=1;LL x,r;for(i=2;i*i<=n;i++)if(n%i==0){x=1;r=0;while(n%i==0){n/=i;x*=i;r++;}s*=(r+1)*x-r*x/i;}if(n>1)s*=(2*n-1);printf("%lld\n",s);}return 0;}
0 0
- POJ 2480 : Longge\'s problem - gcd之和
- POJ 2480 Longge's Problem
- poj 2480 Longge's problem
- poj 2480 Longge's problem
- POJ 2480 Longge's problem
- POJ 2480 Longge's problem
- POJ 2480 Longge's problem
- POJ 2480 Longge's problem(积性函数之欧拉函数与gcd)
- POJ 2480 Longge's problem(数论)
- POJ 2480 Longge's problem(数论)
- POJ 2480 Longge's problem [ 求 Σgcd(i,n)(1<=i<=n) ] [欧拉函数]
- POJ 2480 Longge's problem 欧拉函数
- POJ 2480 Longge's problem(神奇欧拉函数)
- POJ 2480 Longge's problem (欧拉函数)
- POJ 2480 Longge's problem 积性函数
- POJ 2480 Longge's problem (欧拉函数)
- (poj 2480 Longge's problem)<欧拉函数>
- 【poj】 2480 Longge's problem (欧拉函数)
- POJ 2478 : Farey Sequence - 欧拉函数
- POJ 3090 : Visible Lattice Points - 欧拉函数
- iOS Splash以及更新提示
- POJ 2992 : Divisors - 求组合数的因子个数
- java写文件时,输出不完整的原因以及解决方法close()或flush()
- POJ 2480 : Longge\'s problem - gcd之和
- POJ 3696 : The Luckiest number - 欧拉函数,快速幂[数论好题]
- POJ 2183 : Bovine Math Geniuses - 平方取尾法
- POJ 1107 : W\'s Cipher - 密码,字符串模拟
- POJ 2159 : Ancient Cipher - 密码模拟
- POJ 3518 : Prime Gap - 素数筛
- POJ 1032 : Paliament - 整数分解
- POJ 1607 /ZOJ 1216 : Deck - 整齐输出
- POJ 3132 / ZOJ 2822 : Sum of Different Primes - 动态规划,01背包,素数筛