poj 2480 Longge's problem 积性函数性质+欧拉函数

题意:

求f(n)=∑gcd(i, N) 1<=i <=N.

分析:

f(n)是积性的数论上有证明(f(n)=sigma{1<=i<=N} gcd(i,N) = sigma{d | n}phi(n / d) * d ,后者是积性函数),可以这么解释:当d是n的因子时,设1至n内有a1,a2,..ak满足gcd(n,ai)==d,那么d这个因子贡献是d*k,接下来证明k=phi(n/d):设gcd(x,n)==d,那么gcd(x/d,n/d)==1,所以满足条件的x/d数目为phi(n/d),x的数目也为phi(n/d)。

代码:

//poj 2480
//sep9
/*
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 <iostream>
using namespace std;
typedef long long ll;

int main()
{
	ll n;
	while(scanf("%lld",&n)==1){
		ll ans=n;
		for(ll i=2;i*i<=n;++i){
			if(n%i==0){
				ll a=0,p=i;
				while(n%p==0){
					++a;
					n/=p;
				}
				ans=ans+ans*a*(p-1)/p;
			}
		}
<span style="white-space:pre">		</span>if(n!=1)
<span style="white-space:pre">			</span>ans=ans+ans*(n-1)/n;
		printf("%I64d\n",ans);
	}
	return 0;
}
 

poj 2480 Longge's problem 积性函数性质+欧拉函数

时间: 2024-08-06 20:08:19

poj 2480 Longge's problem 积性函数性质+欧拉函数的相关文章

POJ 2480 Longge&#39;s problem 积性函数

题目来源:POJ 2480 Longge's problem 题意:求i从1到n的gcd(n, i)的和 思路:首先如果m, n 互质 gcd(i, n*m) = gcd(i, n)*gcd(i, m) 这是一个积性函数积性函数的和还是积性函数 由欧拉函数知识得 phi(p^a) = p^a - p^(a-1) p是素数 a是正整数 得到最终答案f(n) = f(p1^a1)*f(p2^a2)*...*f(pn^an) 其中f(p^a) = a*(p^a-p^(a-1))+p^a #includ

poj 2480 Longge&amp;#39;s problem 积性函数性质+欧拉函数

题意: 求f(n)=∑gcd(i, N) 1<=i <=N. 分析: f(n)是积性的数论上有证明(f(n)=sigma{1<=i<=N} gcd(i,N) = sigma{d | n}phi(n / d) * d ,后者是积性函数),能够这么解释:当d是n的因子时,设1至n内有a1,a2,..ak满足gcd(n,ai)==d,那么d这个因子贡献是d*k,接下来证明k=phi(n/d):设gcd(x,n)==d,那么gcd(x/d,n/d)==1,所以满足条件的x/d数目为phi(

poj 2480 Longge&#39;s problem [ 欧拉函数 ]

传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2416 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms.

POJ 2480 Longge&#39;s problem (欧拉函数+乘性函数)

Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7343   Accepted: 2422 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now

[poj 2480] Longge&#39;s problem 解题报告 (欧拉函数)

题目链接:http://poj.org/problem?id=2480 题目大意: 题解: 我一直很欣赏数学题完美的复杂度 #include<cstring> #include<algorithm> #include<cstdio> #include<iostream> #include<cmath> using namespace std; typedef long long ll; const int N=(1<<31)+15;

题解报告:poj 2480 Longge&#39;s problem(欧拉函数)

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. 

POJ 2480 Longge&#39;s problem

gcd(i,n)=pgcd(i/p,n/p)=p若p是n的约数,那么gcd(i,n)==p的有φ(n/p)∑ i*euler(n/i)+(n/i)*euler(i)   (n%i==0) #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<map> #i

【欧拉函数】欧拉函数前缀和

转自http://www.cnblogs.com/chanme/p/4457200.html H.   Game Alice likes to play games. One day she meets such a game. There are N * N switches arranged in an N * N array. Pressing a switch would change its state, from off to onor from on to off. In addi

POJ 2480 Longge&amp;#39;s problem 积性函数

题目来源:POJ 2480 Longge's problem 题意:求i从1到n的gcd(n, i)的和 思路:首先假设m, n 互质 gcd(i, n*m) = gcd(i, n)*gcd(i, m) 这是一个积性函数积性函数的和还是积性函数 由欧拉函数知识得 phi(p^a) = p^a - p^(a-1) p是素数 a是正整数 得到终于答案f(n) = f(p1^a1)*f(p2^a2)*...*f(pn^an) 当中f(p^a) = a*(p^a-p^(a-1))+p^a #includ