"Mobius inversion"

Introduced

In consideration of a function \ (F (n) = \ sum \ limits_ {d | n} f (d) \) , it is assumed known function \ (F. \) , Can not pass a number of \ (F (i) \) addition and subtraction to get \ (f (j) \) it? After the discovery seems to be to find the law, and seems to use the \ (i \) is \ (j \) factor. Thus, we can not pass to each factor \ (F \) multiplied by a coefficient can be 0 or 1 or -1, so to get \ (f (j) \) it? That is, we wonder if there is a function \ (\ MU \) enables \ (f (n) = \ sum \ limits_ {d | n} \ mu (d) F (\ dfrac {n} {d}) \ ) it? We call this process the inversion, where \ (\ mu \) is the Mobius function.

Mobius inversion

Suppose inversion formula \ [F (n) = \ sum \ limits_ {d | n} f (d) \ xrightarrow [] { inversion} f (n) = \ sum \ limits_ {d | n} \ mu (d) F (\ dfrac { n} {d}) \] founded
see if we can launch \ (\ mu \)

\[f(n)=\sum\limits_{d|n}\mu(d)F(\dfrac{n}{d})=\sum\limits_{d|n}\mu(d)\sum\limits_{i|\frac{n}{d}}f(i)=\sum\limits_{d|n}f(d)\sum\limits_{i|\frac{n}{d}}\mu(i)\]

To set up such that the above equation, then \ [\ sum \ limits_ {i | \ frac {n} {d}} \ mu (i) = [\ dfrac {n} {d} == 1] \]

I.e. \ [\ sum \ limits_ {i | n} \ mu (i) = [n == 1] \]

So we define the Möbius function.

Mobius function \ (\ mu \) defined

\[\sum\limits_{i|n}\mu(i)=[n==1]\]

Mobius function of nature

[ 性质 1 ] \(\mu(d)=\begin{cases}1& d=1\\(-1)^k& d=p_1*p_2*...*p_k\\0& otherwise\end{cases}\)

prove:

Suppose this property is true, then functions to permit defined明莫比乌斯\ [\ sum \ limits_ {i | n} \ mu (i) = [n == 1] \]

\ (n \ 1 =) Apparently.

\ (n> 1 \) when the \ (n-\) decomposition of the quality factor obtained \ (n-P_1 ^ = {P_2 Y_1} * ^ * ... *} {Y_2 P_K Y_k ^ {} \) . Any number of a prime number exceeding \ (1 \) when a certain value is a function of Mobius \ (0 \) can be disregarded. We only need to consider how many prime factors prime factor index are \ (1 \) . Thus the above equations can be reduced to \ [\ sum \ limits_ {i = 0} ^ {k} C ^ {i} _ {k} * (- 1) ^ i \]

Using the binomial theorem \ [\ sum \ limits_ {i = 0} ^ {k} \ binom {k} {i} (- 1) ^ i1 ^ {ki} = [(- 1) +1] ^ k = 0 \]

[Properties 2] \ (\ MU \) function is a multiplicative function: \ (\ MU (m * n-) = \ MU (m) * \ MU (n-) \) where \ ((m, n) = 1 \ )

prove:

\(m=p_1^{x_1}*p_2^{x_2}*...*p_k^{x_k}\)\(n=q_1^{y_1}*q_2^{y_2}*...*q_t^{y_t}\)

\(m*n=p_1^{x_1}*p_2^{x_2}*...*p_k^{x_k}*q_1^{y_1}*q_2^{y_2}*...*q_t^{y_t}\)

When \ (\ mu (m) = 0 or \ mu (n) = 0 \ ) , the constant presence of a \ (I \) satisfies \ (x_i> 1 \) or \ (y_i>. 1 \) , so \ ( \ mu (m * n) = 0 \) established

When \ (\ mu (m), \ mu (n) \) the same number when, \ (K, T \) have the same parity, the \ (k + t \) is even, \ (\ mu (m * n) = 1 \) established

When \ (\ mu (m), \ mu (n) \) when the opposite sign, \ (K, T \) different parity, the \ (k + t \) is odd, therefore \ (\ mu (m * n) = - 1 \) established


Seeking Mobius function

Usually quadrature function of Euler mesh. Complexity \ (O (n) \)

inline void getMobius(){
    mu[1] = 1; //μ函数的1是特殊情况 
    for(int i = 2; i <= 1e6; ++i){
        if(!b[i]){
            prime[++tot] = i;
            mu[i] = -1; //质数的μ值一定为-1 
        }
        for(int j = 1; j <= tot; ++j){
            if(i * prime[j] > 1e6) break;
            b[i * prime[j]] = 1;
            if(i % prime[j] == 0){
                mu[i * prime[j]] = 0;//i中已经包括了prime[j] 
                break;
            }
            else{
                mu[i * prime[j]] = -mu[i];//不能整除,意味着i中原没有prime[j]这个素因子 
            }
        }
    }
}

Mobius inversion formula

By definition, there are:

[Equation. 1]: \ [F. (N-) = \ SUM \ limits_ {D |} n-F (D) \ xrightarrow [] {inversion} f (n) = \ sum \ limits_ {d | n} \ mu ( d) F (\ {n} dfrac {d}) \]

[Equation 2]: \ [F. (N-) = \ SUM \ {n-limits_ | D} F (D) \ xrightarrow [] {inversion} f (n) = \ sum \ limits_ {n | d} \ mu ( \ dfrac {d} {n} ) F (d) \]


## Question one

\[\sum\limits_{i=1}^{A}\sum\limits_{j=1}^{B}[gcd(i,j)==k]\]

solution:

\[f(x)=\sum\limits_{i=1}^{A}\sum\limits_{j=1}^{B}[gcd(i,j)==x]\]

Obviously \ (f (k) \) is the answer.

Configuration \ [F (x) = \ sum \ limits_ {x | d} f (d) \]

\[F(x)=\sum\limits_{x|d}\sum\limits_{i=1}^{A}\sum\limits_{j=1}^{B}[gcd(i,j)==d]\]\[=\sum\limits_{i=1}^{A}\sum\limits_{j=1}^{B}[x|gcd(i,j)]\]

Obtained by the inversion \ [f (x) = \ sum \ limits_ {x | d} \ mu (\ dfrac {d} {x}) F (d) \]

The answer is \ [f (k) = \ sum \ limits_ {k | d} \ mu (\ dfrac {d} {k}) F (k) \]

Consider \ (F (x) \) meaning, is the number of all pairs \ (x \) the number of multiples. Release can \ (F (x) = \ left \ lfloor \ dfrac {A} {x} \ right \ rfloor \ cdot \ left \ lfloor \ dfrac {B} {x} \ right \ rfloor \)

由此\[f(k)=\sum\limits_{k|d}\mu(\dfrac{d}{k})\left \lfloor \dfrac{A}{k} \right \rfloor \cdot \left \lfloor \dfrac{B}{k} \right \rfloor\] \[f(k)=\sum\limits_{i}\mu(i)\left \lfloor \dfrac{A}{k} \right \rfloor \cdot \left \lfloor \dfrac{B}{k} \right \rfloor\]

The so-called block divisible, it is to use a method in \ (O (\ sqrt {n }) \) obtains the complexity \ [\ sum \ limits_ {i = 1} ^ {n} \ left \ lfloor \ dfrac {n} {i} \ right \ rfloor \] we found that when \ (I \) close, there may be many duplicate values. Thought divisible block is to be reckoned with all duplicate values.

It can prove no more than a total of \ (2 \ sqrt {n} \) th values. It can prove value \ (I \) last denominator are \ (N \) / \ ((N \) / \ (I) \) a. It is only necessary to take a period of each segment, and the pointer to jump to the next section

Looking back at the Mobius inversion. If we come to the form of such inversion formula \ [f (n) = \ sum \ limits_ {n | d} ^ {Min (A, B)} \ mu (\ dfrac {d} {n}) \ left \ lfloor \ dfrac {a } {n} \ right \ rfloor * \ left \ lfloor \ dfrac {B} {n} \ right \ rfloor \] there are two divisible by the formula, how to use divisible block optimize?

Then still using a single divisibility of thought. Each block requires \ (\ left \ lfloor \ dfrac {A} {n} \ right \ rfloor \) and \ (\ left \ lfloor \ dfrac {B} {n} \ right \ rfloor \) are the same. So every time we should jump to the front of the separate section, so as to satisfy both of the same value

The only question now is to deal with \ (\ mu \) a, \ (\ mu \) value is not continuous, if it can be achieved by a method \ (\ mu \) into a prefix and similar things, you can directly calculated.

The identity transformation equation. Order \ (K = \ dfrac {D} {n-} \) : \ [\ SUM \ limits_ {n-| D} \ MU (K) \ left \ lfloor \ dfrac {A} {NK} \ right \ rfloor * \ left \ lfloor \ dfrac {B} {nk} \ right \ rfloor \] actually \ (K \) meaning that \ (D \) of \ (n-\) several times, thereby eliminating the need enumeration \ (D \) , direct enumeration \ (K \) can, in the range of \ (NK \ Leq Min (A, B) \) . May wish to \ (A, B \) are in addition to the \ (n-\) . That \ (A '= \ dfrac {A} {n-}, B' = \ dfrac {B} {n-} \) : \ [\ SUM \ limits_ {K =. 1} \ MU (K) \ left \ lfloor \ dfrac {A '} {k} \ right \ rfloor * \ left \ lfloor \ dfrac {B'} {k} \ right \ rfloor \]

At this point, \ (\ MU \) has been synchronized and in addition to style. Therefore only require pretreatment \ (\ mu \) prefix and can

Guess you like

Origin www.cnblogs.com/qixingzhi/p/11137551.html