模板题,没啥好讲的。
A
C
C
o
d
e
\mathrm{AC \ Code}
AC Code
#include<bits/stdc++.h>
#define maxn 2000005
#define LL unsigned long long
using namespace std;
LL n,K=3,s[maxn],a[maxn];
int id,sn,cnt_pr,pr[maxn];
int ID(LL a){ return a<=sn?a:id-n/a+1; }
LL Sum(LL n,int b){
if(n<pr[b]) return 0;
LL r = (K+1) * (s[ID(n)]-s[pr[b-1]]);
for(int i=b;i<=cnt_pr&&1ll*pr[i]*pr[i]<=n;i++) for(LL x=pr[i],f=K+1;x*pr[i]<=n;x*=pr[i],f+=K)
r += f * (Sum(n/x,i+1)) + f + K;
return r;
}
int main(){
int T;
for(scanf("%d",&T);T--;){
scanf("%llu",&n);sn=sqrt(n),cnt_pr=id=0;
for(LL i=1;i<=n;i++) a[++id]=(i=(n/(n/i))),s[id]=i-1;
for(int i=1;i<=sn;i++) if(s[i]^s[i-1]) for(LL j=id,LIM=1ll*(pr[++cnt_pr]=i)*i,t0=s[i-1];a[j]>=LIM;j--)
s[j] -= s[ID(a[j]/i)] - t0;
printf("%llu\n",Sum(n,1)+(n>=1));
}
}