Mobius inversion simple application # 3

The first two links (in fact, the first chapter do not see also, that some board):

Mobius inversion simple application # 1

Mobius inversion simple application # 2

Example 6:

求:\(\sum\limits_{i=1}^n\sum\limits_{j=1}^md(i\times j)\)

There is a formula: \ (D (I \ J Times) = \ SUM \ limits_ {X | I} \ SUM \ limits_ {Y | J} [\ GCD (X, Y) =. 1] \)

Obviously, it is true, then it can be converted into a strange equation we are familiar with \ (\ gcd \) friends.

\(=\sum\limits_{i=1}^n\sum\limits_{j=1}^m\sum\limits_{x|i}\sum\limits_{y|j}[\gcd(x,y)=1]\)

\(=\sum\limits_{x=1}^n\sum\limits_{y=1}^m[\gcd(x,y)=1]\times\lfloor\frac n x\rfloor\times\lfloor\frac m y\rfloor\)

\(=\sum\limits_{i=1}^n\sum\limits_{j=1}^m[\gcd(i,j)=1]\times\lfloor\frac n i\rfloor\times\lfloor\frac m j\rfloor\)

\(=\sum\limits_{d=1}^n\mu(d)\sum\limits_{i=1}^{\lfloor\frac n d\rfloor}\lfloor\frac n{id}\rfloor\sum\limits_{j=1}^{\lfloor\frac m d\rfloor}\lfloor\frac m{jd}\rfloor\)

We set \ (S (n-) = \ SUM \ limits_. 1} ^ {n-I = \ lfloor \ FRAC Ni \ rfloor \) .

\(=\sum_{d=1}^n\mu(d)\times S[\lfloor\frac n d\rfloor]\times S[\lfloor\frac m d\rfloor]\)

Then you can do \ (O (\ sqrt {n }) \) to solve every problem, \ (O (n-\ Times \ n-sqrt {}) \) pretreatment friends.

Example 7:

求:\(\sum\limits_{i=1}^n\sum\limits_{j=1}^m\varphi(i\times j)\)

First to derive a formula:

\(\varphi(i)\times\varphi(j)=i\prod\limits_{P|i}\frac{P-1}Pj\prod\limits_{P|j}\frac{P-1}P\)

\(~~~~~~~~~~~~~~~~~~~~=ij\prod\limits_{P|i}\frac{P-1}P\prod\limits_{P|j}\frac{P-1}P\)

\(~~~~~~~~~~~~~~~~~~~~=ij\prod\limits_{P|i~or~P|j}\frac{P-1}P\prod\limits_{P|i~and~P|j}\frac{P-1}P\)

\(~~~~~~~~~~~~~~~~~~~~=ij\prod\limits_{P|ij}\frac{P-1}P\prod\limits_{P|\gcd(i,j)}\frac{P-1}P\)

\(\therefore\varphi(i)\times\varphi(j)\times\gcd(i,j)=\varphi(\gcd(i,j))\times\varphi(ij)\)

Then we can further conversion of the equation then:

\(\begin{aligned}&\sum_{i=1}^n\sum_{j=1}^m\frac{\varphi(i)\times \varphi(j)\times\gcd(i,j)}{\varphi(\gcd(i,j))}\\=&\sum_{d=1}^n\frac{d}{\varphi(d)}\sum_{i=1}^{\lfloor\frac{n}{d}\rfloor}\sum_{j=1}^{\lfloor\frac{m}{d}\rfloor}\varphi(id)\times\varphi(jd)\times[\gcd(i,j)=1]\\=&\sum_{d=1}^n\frac{d}{\varphi(d)}\sum_{k=1}^{\lfloor\frac n d\rfloor}\mu(k)\sum_{i=1}^{\lfloor\frac n{kd}\rfloor}\sum_{j=1}^{\lfloor\frac m{kd}\rfloor}\varphi(ikd)\varphi(jkd)\\=&\sum_{T=1}^n\sum_{d|T}\frac{d}{\varphi(d)}\times\mu(\frac T d)\sum_{i=1}^{\lfloor\frac n T\rfloor}\varphi(iT)\sum_{j=1}^{\lfloor\frac m T\rfloor}\varphi(jT)\end{aligned}\)

We have introduced several functions:

  • \(\begin{aligned}F(n)=\sum_{d|n}\frac{d}{\varphi(d)}\times\mu(\frac T d)\end{aligned}\)

    We can (O (n \ log n) \) \ get this thing time.

  • \(\begin{aligned}G(y,x)=\sum_{i=1}^x\varphi(iy)\end{aligned}\)

    We have recurrence formula: \ (G (Y, X) = G (Y,. 1-X) + \ varphi (XY) \)

    May be in the (O (n \ log n) \) \ obtained in time.

  • \(\begin{aligned}S(y,z,x)=\sum_{T=1}^x\sum_{d|T}\frac{d}{\varphi(d)}\times\mu(\frac T d)\sum_{i=1}^{y}\varphi(iT)\sum_{j=1}^{z}\varphi(jT)\end{aligned}\)

    There is also recursive formula: \ (S (Y, Z, X) = S (Y, Z,. 1-X) + F. (X) \ Times G (X, Y) \ Times G (X, Z) \)

Pre-finished these three functions is clearly unrealistic, the memory will be fried.

We set a limit \ (B \) :

  • All \ (\ lfloor \ FRAC Nd \ rfloor \) , \ (\ lfloor \ FRAC MD \ rfloor \) is less than \ (B \) are pretreated, so will be able to \ (O (\ sqrt {n }) \ ) solved within this part of the time.

  • Greater than \ (B \) , we found \ (D <B \) , so we can directly burst count can be in (O (\ lfloor \ frac n B \ rfloor) \) \ solved in time.

The total time complexity analysis:

\(O(n\log n+n\times B^2+q\times(\sqrt n+\lfloor\frac n B\rfloor))\)

Found that when \ (B = 35 \) accessible to most values, done!


To the final exam, plus recently there are some people caught playing the game, so tomorrow will not let the room came.

"Mobius inversion simple application # 4", should be shelved for a long time, and even more free now.

Guess you like

Origin www.cnblogs.com/WR-Eternity/p/11006008.html