concept
Domain is a positive integer function is a function of number theory.
Provided p, q coprime , f [P * Q] = f [P] * f [Q] , f is called a multiplicative function. The divisor, Euler, Mobius.
Any of P, Q, f [P * Q] = f [P] * f [Q] , called multiplicative function f is complete. As one function, i.e., f [i] = 1.
We generally use linear sieve can be pre-multiplicative function.
Euler phi
void phii() { phi[1]=1; for(int i=2;i<=maxn;i++) { if(!not_prime[i]) { prime[++tot]=i; phi[i]=i-1; } for(int j=1;j<=tot&&prime[j]*i<=maxn;j++) { not_prime[i*prime[j]]=1; if(i%prime[j]==0) { Non [i * prime [j]] = non [i] * prime [j]; break ; } Else non [i * prime [j]] = non [i] * non [prime [j]]; } } }
Mobius mu
void init() { notp[1]=1;mu[1]=1; for(int i=2;i<=maxn;++i) { if(!notp[i])prime[++tot]=i,mu[i]=-1; for(LL j=1;j<=tot&&i*prime[j]<=maxn;++j) { notp[i*prime[j]]=1; if(i%prime[j]==0) { mu[i*prime[j]]=0;//Comprising a square- BREAK ; } the else MU [Prime * I [J]] = - MU [I]; // number of prime ++ } } }
Divisor
Submultiple there are two, one is seeking the number of divisors, one is seeking divisors
(Do not want their hands to fight the cause) is taken from this blog
Do not play when 1 forgot
void the init () { NOTP [ . 1 ] = . 1 ; YS [ . 1 ] = . 1 ; dd [ . 1 ] = . 1 ; // number divisor ys, dd minimum number of prime factors for (Re int I = 2 ; I <= 50000 ; ++ I) { IF (NOTP [I]) Prime [TOT ++] = I, YS [I] =! 2 , dd [I] = . 1 ; for (LL J = Re . 1 ; J < Prime && * I TOT = [J] <= 50000 ; ++ J) { NOTP [I * Prime [J]] = . 1 ; IF (I% Prime [J] == 0 ) { YS [I * Prime [J]] YS = [I] / (dd [I] + . 1 ) * (dd [I] + 2 ); dd [I * prime [J]] = dd [I] + . 1 ; BREAK ; } the else { YS [I * prime [J]] YS = [I] * 2 ; // (multiplicative function of the nature, the number of prime divisor of the number of 2 =) dd [i * prime [j]] = . 1 ; // prime [J] is the i and i * prime [j] is the smallest prime factor } } } }
void the init () { NOTP [ . 1 ] = . 1 ; sd [ . 1 ] = . 1 ; sp [ . 1 ] = . 1 ; // about sd and number, the polynomial sp smallest prime factors (which may be understood as composed of the minimum quality factor divisor number and the bar) for (Re int I = 2 ; I <= 50000 ; ++ I) { IF ! (NOTP [I]) Prime [TOT ++] = I, SD [I] = I + . 1 , SP = I + . 1 ; for (LL J = Re . 1 ; J <= TOT Prime && * I [J] <= 50000 ; ++ J) { NOTP [I * Prime [J]] = . 1; if(i%prime[j]==0) { sd[i*prime[j]]=sd[i]/sp[i]*(sp[i]*prime[j]+1); sp[i*prime[j]]=sp[i]*prime[j]+1; break; } else { sd[i*prime[j]]=sd[i]*sd[prime[j]]; sp[i*prime[j]]=prime[j]+1; } } } }