poj2480 Longge's problem
来源:互联网 发布:编程大括号 编辑:程序博客网 时间:2024/06/06 21:38
Description
Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N.
"Oh, I know, I know!" Longge shouts! But do you know? Please solve it.
"Oh, I know, I know!" Longge shouts! But do you know? Please solve it.
Input
Input contain several test case.
A number N per line.
A number N per line.
Output
For each N, output ,∑gcd(i, N) 1<=i <=N, a line
Sample Input
26
Sample Output
315
设函数g(n) = gcd(i,n) (1<=i<=n),由积性函数的定义,g(n)=g(m1)*g(m2) (n=m1*m2 且 (m1, m2)= 1),所以g是积性函数。由具体数学上的结论,积性函数的和也是积性的。所以f(n) = ∑gcd(i, n)也是积性函数。由初等数论中的定理,如果f(n)是不恒为0的数论函数,n>1时 n=p1^a1*p2^a2*...*ps^as,那么f(n)是积性函数的充要条件是f(1)=1,及f(n) = f(p1^a1)*f(p2^a2)*...f(pr^ar)。所以只要求f(pi^ai)就好,如果d是n的一个约数,那么1<=i<=n中gcd(i,n) = d的个数是phi(n/d),即n/d的欧拉函数
f(pi^ai) = Φ(pi^ai)+pi*Φ(pi^(ai-1))+pi^2*Φ(pi^(ai-2))+...+pi^(ai-1)* Φ(pi)+ pi^ai *Φ(1)
= pi^(ai-1)*(pi-1) + pi*pi^(ai-2)*(pi-1)....+pi^ai
= pi^ai*(1+ai*(1-1/pi))
f(n) = p1^a1*p2^a2...*pr^ar*(1+a1*(1-1/p1))*(1+a2*(1-1/p2))*...
= n*(1+a1*(1-1/p1))*(1+a2*(1-1/p2))*...
#include<stdio.h>#include<string>#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <vector>#include <queue>#include <cstdio>#include <cmath>#include <string>#include <stack>#include <cctype>using namespace std;int main(){ __int64 n; while(~scanf("%I64d",&n)) { __int64 i,j,k,l,ans,v; ans=n; v=sqrt(n); for(i=2; i<=v; i++) { if(n%i==0) { k=0; l=i; while(n%l==0) { k++; n/=l; } ans+=ans*k*(l-1)/l; } } if (n!=1) { ans = ans + ans*(n-1)/n; } printf("%I64d\n", ans); } return 0;}
- poj2480 Longge's problem
- POJ2480 Longge's problem
- POJ2480《Longge's problem》题解
- POJ2480 Longge's problem【乘性函数】
- POJ2480 Longge's problem 欧拉函数应用
- POJ2480 Longge's problem 欧拉函数的应用 && 积性函数
- POJ2480——Longge's problem(数论,欧拉函数d)
- longge's problem
- Longge's problem-数论
- POJ 2480 Longge's Problem
- soj 1085. Longge's problem
- Sicily 1085.Longge's problem
- sicily 1085. Longge's problem
- poj 2480 Longge's problem
- Sicily 1085. Longge's problem
- poj 2480 Longge's problem
- POJ 2480 Longge's problem
- POJ 2480 Longge's problem
- jquery qtip demo
- 关于Linux静态库和动态库的分析
- 判断某一点在直线左右侧的方法...
- Poj 1523 SPF 关节点
- java模拟链表
- poj2480 Longge's problem
- Z-Stack网络参数配置
- 03-php雇员管理系统-实现显示用户名称
- axFramerControl控件对EXCEL操作的一些方法!
- 求解区间最值的ST算法
- 使用JSON来进行Ajax开发(一)
- 在secureCRT中让vi 彩色显示
- 程序的命令行编译
- javascript的拖放