Learning algorithm: Mobius inversion

[Front] knowledge

[Block] Number Theory

[Problems] Description request for i from 1 to n, i and k divisible

[Solution] obvious, within a range of 1 to n, the value of i k is divisible by the same, so we just need to find the range, and then multiplied by the contribution of this segment with the number of intervals (ie i k is divisible value)

  

1   int res = 0 ;
2   for ( int d = 1 ; d <= nn;) {
 3          int than = NN / (nn / d);
4          int one = min (than, nn);
 5          res + = (nn / d) (d + en) * (A + 1 -d) / 2 ;
6          d = A + 1 ;
7      }
View Code

[Multiplicative function]

  A function F (X), when satisfying a, b coprime with F (a * b) = F (a) * F (b), called the function F (X) is a multiplicative function

  Multiplicative function generally may be ascertained by linear or mesh sieve Angstroms time constant

 

  Here are a few of the more important and commonly used multiplicative function

  φ (x): the Euler function, less number of values ​​x and x prime and

  Ι (x): a function value as a function of the constant

  id (x): function value is equal to a function of x

  ε (x): membership function is equal to 1 only when x is 1, the remaining cases are 0

 

Mobius function []

ti refers to a power of the prime factors of the i-th

Function definition is:

1. When 1, the function value is equal to n == 1

2. When the case where there is a power of prime factors greater than 1, function 0

3. When a power of all of the prime factors are equal to 1, the function is (-1) k-th, k refers to the number of different quality factors

Code 1 ~ MAXN Mobius seeking function board

 

 1 int mu[MAXN], prime[MAXN],vis[MAXN],sum[MAXN];
 2 int cnt = 0;
 3 void init()
 4 {
 5     mu[1] = 1;
 6     cnt = 0;
 7     for (int i = 2; i < MAXN; i++)
 8     {
 9         if (vis[i] == 0)
10         {
11             mu[i] = -1;
12             prime[++cnt] = i;
13         }
14         for (int j = 1; j <= cnt && i*prime[j]<MAXN; j++)
15         {
16             vis[prime[j] * i] = 1;
17             if (i%prime[j] == 0)
18             {
19                 mu[i*prime[j]] = 0;
20                 break;
21             }
22             else
23             {
24                 mu[i*prime[j]] = -mu[i];
25             }
26         }
27     }
28     for (int i = 1; i < MAXN; i++)
29         sum[i] = sum[i - 1] + mu[i];
30 }
View Code

 

Mobius function has a special property :

So that F (x) is equal, all the factors x and a function of Mobius

The function value F (x) is equal to 1 only when x is 1, the remaining cases are 0

(Prime quality factor may permit the use of the nature of it, is not given here proof)

 

[Dirichlet convolution]

  Dirichlet convolution of two functions is operated, the function f, g equals convolution, so that d is a factor n with f (d) * g (n / d), and all of the factors is the n f, g of Dirichlet convolution

  There are nature:

  

 

  Dirichlet convolution defined by the above we can get the following conclusions:

 [A] Conclusion understood from the special nature of Mobius function, there are I * μ == ε [Conclusion 2] and the like Mobius function, Euler function also has a special properties:  
 

   So that F (x) equal to the Euler function and all of the factors of x 

   The function F (x) is x

(Euler function definition can permit it, do not give proof here)

   1.     f * I == id

   2. f == id * m

  Derivation and conclusions are as follows:

 

Mobius inversion []

  

(摘自https://oi-wiki.org/math/mobius/

  推导过程如下

 

 

      

 

Guess you like

Origin www.cnblogs.com/rentu/p/11242029.html