[Linear sieve of common integrable functions] "learning notes"

Source: Internet
Author: User

"Euler function"

φ (n) =n (1-1/P1) (1-1/P2) ... (1-1/PK)

Easy to find P[j]|i when Phi[i*p[j]]=phi[i]*p[j] because Phi[i] n is n*p[j]/p[j], the rest of the same

Proof: http://www.cnblogs.com/candy99/p/6200660.html

voidsieve () {phi[1]=1;  for(intI=2; i<=n;i++){        if(!Vis[i]) {p[++m]=i; Phi[i]=i-1; }         for(intj=1; j<=m&&i*p[j]<=n;j++) {vis[i*p[j]]=1; if(i%p[j]==0) {Phi[i*p[j]]=phi[i]*P[j];  Break; } phi[i*p[j]]=phi[i]* (p[j]-1); }    }     for(intI=1; i<=n;i++) s[i]=s[i-1]+phi[i];}

"About a few numbers"

According to the multiplication principle, the approximate number of n is ∏{I=1...R} (ai+1)

facnum[i*p[j]]=facnum[i]/(minfac[i]+1) * (minfac[i*p[j]]+1) When P[j]|i is available from the upper formula

"Approximate and"

N=p1^a1*p2^a2*...*pr^ar
Then its approximate and =∏{I=1...R} (Σ{J=1..AJ}PI^J)
P[j]|i, get Sumfac[i*p[j]]
Need to divide by σ (p[j]^ (0..minfac[i]))
multiplied by σ (pris[j]^ (0..minfac[k])
where minfac[k]=minfac[i]+1
This opens two auxiliary array records
T1[i]=σ (minfac[i]^ (0..a[minfac[i]))
T2[i]=mindiv[i]^a[minfac[i]]

int notp[n],p[n],mu[n],minfac[n],t1[n],t2[n],sf[n];
voidsieve () {mu[1]=1; sf[1].s=1;  for(intI=2; i<n;i++){        if(!Notp[i]) {p[++p[0]]=i,mu[i]=-1; Minfac[i]=i; Sf[i]=i+1; T1[i]=i+1; T2[i]=i; }         for(intj=1, k;j<=p[0]&& (K=i*p[j]) <n;j++) {Notp[i*p[j]]=1; MINFAC[K]=P[j]; if(i%p[j]==0) {Mu[i*p[j]]=0; T2[K]=t2[i]*P[j]; T1[K]=t1[i]+T2[k]; SF[K]=sf[i]/t1[i]*T1[k];  Break; } mu[i*p[j]]=-Mu[i]; T1[K]=1+P[j]; T2[K]=P[j]; SF[K]=sf[i]*Sf[p[j]]; }    }}

[Linear sieve of common integrable functions] "learning notes"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.