Euler functions and Möbius inversion (Mobius)

Source: Internet
Author: User

These days to study the past has been plagued by a long time of Möbius inversion, although he is not very good at learning now, simple to write a summary of it, hey, have not learned to master I write summary seems to be very much, Euler function now also the system of the collation of a good one, Euler function

1. Definition: in number theory, for positive integer n, the Euler function is less than n of a positive integer number with n coprime (φ (1) =1). This function is named after the first researcher Euler (Euler ' so totient function), which is also called Euler's totient functions, φ, Euler quotient, and so on. For example φ (8) = 4, because 1,3,5,7 are both and 8 coprime. The fact and Lagrange theorem of Euler's function are the proof of Euler theorem.
set N as a positive integer, with φ (n) representing the number of positive integers not exceeding n and N, called the Euler function value of n
Φ:n→n,n→φ (N) is called Euler function.
2. Function Contents:
Formula
Where P1, P2......pn is all factorization of x, X is an integer that is not 0.

Some of the properties of Euler's functions can be found in the following blogs:
Find the inverse of the blog

3. Then give some code to find Euler functions:(see this blog post)
(1) The code of the Sieve method to find Euler's function:

Sieve Euler functions

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=3E6+10;

int euler[n];


void Geteuler ()
{
    memset (euler,0,sizeof (Euler));
    Euler[1]=1;
    for (int i=2, i<n; i++)
    {
        if (euler[i]==0)
        {for
            (int j=i; j<n; j + +)
            {
                if (euler[j]= =0)
                    Euler[j] = j;
                EULER[J] = euler[j]/i* (i-1);

}}} int main ()
{
    geteuler ();
    int n;
    cin>>n;
    cout<<euler[n]<<endl;
    return 0;
}

(2) Euler function for single number:

The Euler function of a single number is called direct

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define LL Long long
const int n=3e6+10;

ll Eular (ll N)
{
    ll ans = n;
    for (int i = 2; i*i <=n; i++)
    {
        if (n%i==0)
        {
            ans-=ans/i;
            while (n% i = = 0)
                n/= i;
        }
    }
    if (n>1)
        ans-= ans/n;
    return ans;
}

int main ()
{
    int n;
    cin>>n;
    Cout<<eular (n) <<endl;
    return 0;
}

(3) The linear sieve for Euler function (and also the Euler function and the prime number table):

The time complexity of the linear sieve is O (n)//#include <iostream> #include <cstdio> #include <algorithm> #include <cstring
> #include <cmath> using namespace std;
#define LL Long Long const int n=3e6+10;
BOOL Check[n];

int phi[n];//int prime[n];//prime number int tot;
    void phi_and_prime_table (int x) {memset (check,false,sizeof (check));
    Phi[1]=1;
    tot = 0;
            for (int i = 2; i <= x; i++) {if (!check[i])//i is the prime number {prime[tot++] = i;
        Phi[i] =i-1;
            } for (int j=0; j < tot; J + +) {if (i* prime[j]>x) break;
            Check[i*prime[j]]=true;
                if (i% prime[j] = = 0) {phi[i*prime[j]]=phi[i] * prime[j];
            Break
            } else {Phi[i *prime[j]]=phi[i] * (prime[j]-1);

    }}}} int main () {int n;
    cin>>n;
    Phi_and_prime_table (n); Cout<<phi[n]<<endl;
return 0; }

(4) Decomposition factorization to find Euler function: No detailed code is given here.

The above is the Euler function of the knowledge points and code template, and then began to introduce Möbius inversion two, Möbius inversion

1. Theorems: F (n) and F (n) are two functions that are defined on a non-negative integer set, and satisfy a condition
Then we get the conclusion

where U (d) is the Möbius function, it is defined as follows:
(1) if d=1, then U (d) =1
(2) If d=p1*p2*p3 *pk,pi are all cross-prime, then U (d) = ( -1) ^k
(3) Other cases U (d) =0

for the U (d) function There are the following common properties:
(1) for any positive integer n
(2) for any positive integer n

2. Proof:

3. Linear filter to find Möbius function:

Linear sieve for the inverse of the UFA
//
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define LL Long long
const int n=3e6+10;
ll Mob[n];
ll Vis[n];
ll prime[n];//primes
ll cnt;

void Mobius ()
{
    memset (prime,0,sizeof (Prime));
    memset (mob,0,sizeof (Mob));
    memset (vis,0,sizeof (Vis));
    MOB[1] = 1;
    CNT = 0;
    for (ll i = 2; I <N; i++)
    {
        if (!vis[i])
        {
            prime[cnt++] = i;
            mob[i]=-1;
        }
        for (ll J=0; J < cnt&&i*prime[j]<n; J + +)
        {
            vis[i*prime[j]]=1;
           if (I%prime[j])
                mob[i*prime[j]]=-mob[i];
           else{
            mob[i*prime[j]]=0;break
;

}}} int main ()
{
    int n;
    Mobius ();
    cin>>n;
    cout<<mob[n]<<endl;
    return 0;
}

Well, let's just write about this, and when I get to know you better these days, I'll come back.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.