1 #include<cstdio> 2 #include<iostream> 3 #define M 1000008 4 using namespace std; 5 long long tot,f[M],sum[M],ans,n,b[M],p[M]; 6 int main() 7 { 8 scanf("%d",&n); 9 ans=1; 10 for(int i=2;i<=n;i++) 11 { 12 if(!b[i]) 13 { 14 tot++; 15 p[tot]=i; 16 sum[i]=1; 17 f[i]=2; 18 } 19 for(int j=1;j<=tot;j++) 20 { 21 if(i*p[j]>n) 22 break; 23 b[i*p[j]]=1; 24 if(i%p[j]) 25 { 26 f[i*p[j]]=f[i]*2; 27 sum[i*p[j]]=1; 28 } 29 else 30 { 31 f[i*p[j]]=f[i]/(sum[i]+1)*(sum[i]+2); 32 sum[i*p[j]]=sum[i]+1; 33 } 34 } 35 ans+=f[i]; 36 } 37 printf("%lld ",ans); 38 return 0; 39 }
权当练习下线性筛求约数个数。