Provincial team training to watch the teacher on the stage told a morning Möbius inversion, the whole person is ignorant, because I can not see the blackboard and projection!!!
Home originally wanted to study at night, but he was a procrastination patient, only knocked the μ function ( said more are tears Qaq)
The idea of the code is as follows:
1. The count is due to the number of times because there will be 1 , so each time you need to take the symbol counter;
2. Why is it possible to calculate μ (a) =0 ? The proof is as follows ( if the error can be pointed out, but don't hit me qaq):
① proof: Known a=p1*p2*p3*...*pn*pi (1<=i<=n and p as prime number )
Then μ (a) =μ (1) μ (p1) +μ (p2) + ... μ (n) +μ (P1P2) +μ (P1P3) + ... μ (PN-1PN) ( Why not list μ (pi^2* ...) It? Because its value is 0, it does not affect the result )
It can be found that the μ () value in the above is 1, -1 of each have n ( because μ (pi^2) =0), offset,μ (a) is equal to It's 0 .
② Second proof: Known a=p1^b1*p2^b2*p3^b3*...*pn^bn (bi≠0 and Max (BI) >1) and μ (a) =0
So that a ' =p1^b1*p2^b2*p3^b3*...*pn^bn*pi (1<=i<=n)
μ (a ') =μ (a) =0, because they satisfy the factor J of μ (j) ≠0 is the same, so the μ () value is the same.
And then you're done.
1#include <Set>2#include <cmath>3#include <ctime>4#include <queue>5#include <stack>6#include <cstdio>7#include <vector>8#include <cstring>9#include <cstdlib>Ten#include <iostream> One#include <algorithm> A #defineN 10000001 - using namespacestd; - intMu[n],n; theInlinevoidGet_mu () { - for(intI=1; i<=n;i++){ - if(i==1) mu[i]=1; - Elsemu[i]=0-Mu[i]; + for(intj=i<<1; j<=n;j+=i) -mu[j]+=Mu[i]; + } A } atInlinevoidinit () { -scanf"%d",&n); - Get_mu (); - } - intMain () { -Freopen ("mobius.in","R", stdin); inFreopen ("Mobius.out","W", stdout); - init (); to fclose (stdin); + fclose (stdout); - return 0; the}
[Konjac konjac cultivation Plan] [Template]μ function