Coprime Euler function study notes

Coprime Euler function study notes

Coprime

definition:

\ (\ FORALL A, B \ in \ N \) , if the \ (GCD (A, B) =. 1 \) , called \ (a, b \) prime.

Multiplicative function

definition:

If \ (a, b \) when the prime, there are \ (F (ab &) = F (A) * F (B) \) , then the function called \ (F \) is a multiplicative function.

nature:

If \ (F \) is the product of the function and the fundamental theorem of arithmetic, \ (n-= \ Prod \ limits_. 1} = {I ^ m ^ {P_i} C_i \) , then \ (f (n) = \ Prod \ limits_. 1} = {I MF ^ (^ {P_i} C_i) \) .

Euler function

  • definition:

\ (1 \ sim N \) with \ (N \) prime number is called the Euler function number, referred to as \ (\ varphi (N) \) .

If the fundamental theorem of arithmetic, \ (P_1 = ^ {N} P_2 c_1 and c_2} {^ \ ^ cdots P_m C_m} {\) , then: \ (\ varphi (N) = N * \ FRAC} {p_1-1 {p_1} * \ frac {p_2-1 } {p_2} \ cdots \ frac {p_m-1} {p_m} = N * \ prod \ limits_ { prime number p \ mid N} (1- \ frac {1} {p }) \) .

prove:

Set \ (P \) is \ (N \) prime factors, \ (. 1 \ SIM N \) in \ (P \) multiple consensus \ (N / p \) a. Similarly, if \ (Q \) is \ (N \) is the quality factor, the \ (1 \ sim N \) in \ (Q \) multiples are \ (N / q \) a. If we these \ (N / p + N / q \) number is removed, then the \ (p * q \) multiples are excluded twice, a need to add back. Thus, according to the inclusion and exclusion, \ (N \. 1 \ SIM) is not the \ (N \) containing common prime factors \ (P \) or \ (Q \) the counted number is:

\(N-\frac{N}{p}-\frac{N}{q}+\frac{N}{pq}=N(1-\frac{1}{p})(1-\frac{1}{q})\)

Similarly, we have to \ (N \) of all prime factors of the use of inclusion and exclusion, you can get \ (\ varphi (N) \) .

  • nature
    1. \ (\ forall n> 1,1 \ \ sim n) with \ (n-\) prime number is the sum of \ (n-* \ varphi (n-) / 2 \) .
    2. If \ (a, b \) prime, then \ (\ varphi (ab &) = \ varphi (A) \ varphi (B) \) .
    3. Set \ (P \) is a prime number, if \ (p \ mid n \) and \ (P ^ 2 \ MID n-\) , then \ (\ varphi (n) = \ varphi (n / p) * p \) .
    4. Set \ (P \) is a prime number, if \ (p \ mid n \) and \ (P ^ 2 \ Not | n-\) , then \ (\ varphi (n) = \ varphi (n / p) * (p -1) \) .
    5. \(\sum\limits_{d|n}\varphi(d)=n\)

prove:

Since \ (GCD (n-, X) = GCD (n-, NX) \) , so that the \ (n-\) is not a prime number \ (x, nx \) in pairs, an average value of \ (n / 2 \) . Thus, the \ (n-\) average number is prime \ (n-/ 2 \) , properties \ (1 \) holds.

The calculation formula of Euler function, because \ (GCD (A, B) = 1 \) , except that they do not have (1 \) \ divisor other than, the calculation will not be repeated \ ((1- \ frac {P}. 1} {) \) , properties \ (2 \) holds.

If \ (p \ mid n \) and \ (P ^ 2 \ n-MID \) , then \ (n, n / p \ ) contain the same quality factor, calculated according to Euler's function, both divided quotient is \ (the p-\) , the nature of \ (3 \) was established.

If \ (p \ mid n \) and \ (P ^ 2 \ Not | n-\) , then \ (GCD (n-, n-/ P) =. 1 \) , the \ (\ varphi \) is a multiplicative function to give \ (\ varphi (n-) = \ varphi (n-/ P) * \ varphi (P) \) . Wherein \ (\ varphi (P). 1-P = \) , properties \ (4 \) holds.

Set \ (F (n-) = \ SUM \ limits_ {D |} n-\ varphi (D) \) . Expand multiplication distribution ratio compared reuse \ (\ varphi \) is a multiplicative function, to give: if \ (GCD (n-, m) =. 1 \) , then \ (f (nm) = \ sum \ limits_ {d | nm} \ varphi (d) = (\ sum \ limits_ {d | n} \ varphi (d)) * (\ sum \ limits_ {d | m} \ varphi (d)) = f (n) * f ( m) \) . That \ (F \) is the product of a function, for a single quality factor, \ (F (P ^ m) = \ SUM \ limits_ {D | P ^ m} \ varphi (D) = \ varphi (. 1) + \ varphi (p) + \ varphi (p ^ 2) + \ cdots + \ varphi (p ^ m) \) is coupled with a geometric sequence summing \ (1 \) , the result is \ (P ^ m \) . So \ (F (n-) = \ Prod \ limits_ {I =. 1} ^ MF (P_i ^ {C_i}) = \ Prod \ limits_ {I =. 1} ^ m P_i ^ {C_i} = n-\) , the nature of \ (5 \) was established.

example

Face questions

Luogu P2158 [SDOI2008] honor guard

Solution

Analysis of the subject can be found, in addition to \ ((1,0) \) , \ ((0,1) \) and ((1,1) \) \ than three points, a nail \ ((x, y) \) can be seen, if and only if \ (gcd (x, y) = 1 \) is established when.

As the nail can be seen clearly on \ (y = x \) this line of symmetry, so we can only claim half. For nail lower right of the coordinate system can be seen, satisfy for every \ (2 \ leq x \ leq N \) has \ (. 1 \ Leq Y <X, GCD (X, Y) =. 1 \) . Such \ (y \) number is precisely the \ (\ varphi (the X-) \) .

In summary, the answer to this question is \ (. 3 2 + * \ SUM \ limits_ I = {2} ^ N \ varphi (I) \) . We have to do is to find \ (2 \ sim \ N) Euler function for each number in.

Code

#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
template<class T>void read(T &x)
{
    x=0;char k=getchar();int f=1;
    for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
    for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
    x*=f;
}
int n,ans;
int prime[40005],tot,phi[40005];
bool is_not_pr[40005];
inline void prepare()
{
    phi[1]=1;
    for(int i=2;i<=n;i++)
    {
        if(!is_not_pr[i])
        {
            prime[++tot]=i;
            phi[i]=i-1;
        }
        for(int j=1;j<=tot&&i*prime[j]<n;j++)
        {
            is_not_pr[i*prime[j]]=1;
            if(i%prime[j]==0)
            {
                phi[i*prime[j]]=phi[i]*prime[j];
                break;
            }
            else phi[i*prime[j]]=phi[i]*phi[prime[j]];
        }
    }
}
int main()
{
    read(n);
    if(n==1) printf("0");
    else
    {
        prepare();
        for(int i=2;i<n;i++) ans+=phi[i];
        printf("%d\n",ans*2+3);
    }
    return 0;
}

to sum up

This part of the problem to be good at conversion problem, the problem is simplified to do model, while its expansion - Mobius inversion is more important class of problems, to take the time to take a look.

Guess you like

Origin www.cnblogs.com/TheShadow/p/11401468.html