POJ2480 Productive function

portal


The previous Great God has written very well. Reprinted.

Productive function in number theory: For a function f(n) of a positive integer n, where f(1)=1 and when a and b are relatively prime, f(ab)=f(a)f(b), in In number theory, it is called an integral function. If a function f(n) conforms to f(1)=1, and even if a and b are not coprime, f(ab)=f(a)f(b), then it is called a completely integral function.

Euler function, gcd(n,k) (when k is fixed) are all integral functions

And when i, j are mutually prime, gcd(i*j,m)=gcd(i,m)*gcd(j,m), so gcd(n,k) is an integral function

At the same time, the sum of integral functions is also integral function

Mainly examine a thing called integral function: f(x*y)=f(x)*f(y), which is often seen in middle school mathematics.
Another property of integral functions is that the sum of integral functions is also a integral function.
A formula f(n)=f(p1^a1)*f(p2^a2)*f(p3^a3)*...*f(pk^ak) can be obtained. But at present we don't know what is the use of this formula, 6666666666666666.
Looking at this question again, if n and m are relatively prime, then gcd(i,n*m)=gcd(i,n)*gcd(i,m). ∴gcd(i,n) is an integral function ==>Σgcd(i,n) is an integral function.
Let f(n)=Σgcd(i,n), the problem is transformed to find all f(pi^ai).
Let's find f(pi^ai):
First, it is clear that if p is a divisor of n, then the number of i that satisfies gcd(i,n)==p is Φ(n/p).
Proof: gcd(i,n)==p. Let i=k*p,n=m*p.
Then gcd(k,m)=1, that is, k and m are relatively prime, and the number of i that satisfies the condition is required to find the number of k corresponding to i, that is, to find the Euler function of m, m= n/p, so the number of i that satisfies the condition is Φ(m)=Φ(n/p).
Well, using this principle to find f(pi^ai) is to enumerate each divisor of pi^ai (in fact, pi^t, t<=ai), and then find gcd(i, pi^ai )== the number of i's satisfied by pi^t, so the number*pi^t is part of the required answer.
公式: f(pi^ai)=Φ(pi^ai)+pi*Φ(pi^(ai-1))+pi^2*Φ(pi^(ai-2))+...+pi^ (ai-1)* Φ(pi)+pi^ai*Φ(1);
Here we can simplify the part of finding the Euler function, because there is only one divisor pi in f(pi^ai), so:
Φ(pi^ai)=pi^ai-pi^(ai-1)。
Proof: The number of positive integers less than pi^ai is p^ai - 1;
Among them, the positive integers that are not coprime to pi^ai are (pi*1,pi*2,...,pi*(pi^(ai-1)-1) ) total  pi^(ai-1)-1 indivual.
Φ(pi^ai)=pi^ai -1 -(pi^(ai-1)-1)=pi^ai-pi^(ai-1)
After all, get organized: f (pi ^ ai) = pi ^ ai * (1 + ai * (1-1 / pi)).
Therefore, f (n) = n * (1 + a1 * (1-1 / p1)) * (1 + a2 * (1-1 / p2)) *. …… = n * π (ai * pi + pi) -ai) / pi ;
Problem solved! ! !

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

#define pi acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x,y) memset(x,y,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define W while
#define sgn(x) ((x) < 0 ? -1 : (x) > 0)
#define bug printf("***********\n");
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
const int dx[]= {-1,0,1,0,1,-1,-1,1};
const int dy[]= {0,1,0,-1,-1,1,-1,1};
const int maxn=1005;
const int maxx=1e6+100;
const double EPS=1e-7;
const int mod=998244353;
template<class T>inline T min(T a,T b,T c)
{
	return min(min(a,b),c);
}
template<class T>inline T max(T a,T b,T c)
{
	return max(max(a,b),c);
}
template<class T>inline T min(T a,T b,T c,T d)
{
	return min(min(a,b),min(c,d));
}
template<class T>inline T max(T a,T b,T c,T d)
{
	return max(max(a,b),max(c,d));
}
inline LL Scan()
{
	LL Res=0,ch,Flag=0;
	if((ch=getchar())=='-')Flag=1;
	else if(ch>='0' && ch<='9')Res=ch-'0';
	while((ch=getchar())>='0'&&ch<='9')Res=Res*10+ch-'0';
	return Flag ? -Res : Res;
}
LL val,pri[maxx],vis[maxx];
void init()  
{  
    for(int i=2;i<maxx;i++)  
    {  
        if(!vis[i])pri[val++]=i;  
        for(int j=0;j<val&&i*pri[j]<maxx;j++)  
        {  
            vis[i*pri[j]]=1;  
            if(i%pri[j]==0)break;  
        }  
    }  
}  

LL n;
int main()
{
	init();
	while(~scanf("%lld",&n))
	{
		LL x=n;
		LL ans=n;	
		for(int i=0;i<val&&pri[i]*pri[i]<=n;i++)
		{
			if(n%pri[i]==0)
			{
				LL cnt=0;
				while(n%pri[i]==0)
				{
					n/=pri[i];
					cnt++;
				}
				ans=(ans/pri[i])*(cnt*pri[i]+pri[i]-cnt);
			}
		}
		if(n>1)
		{
			ans/=n;
			ans*=n+n-1;
		}
		cout<<ans<<endl;
	}
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326546638&siteId=291194637