1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| #include<bits/stdc++.h> using namespace std; #define ll long long const int N = 1e5+10; ll g[N<<1],h[N<<1],sn,sq,a[N<<1],n,sum[N<<1]; int prime[N],cnt,id; inline ll Id(ll x){return x<=sn?x:id-n/x+1;} ll SolvePhi(ll a,ll b) { if(a<prime[b])return 0; ll ans = g[Id(a)]-sum[b-1]+(b-1); for(int i=b;i<=cnt&&prime[i]*prime[i]<=a;i++) { ans+=(SolvePhi(a/prime[i],i+1)+prime[i])*(prime[i]-1); for(ll x=prime[i]*prime[i],f=x-prime[i];x*prime[i]<=a;x*=prime[i],f*=prime[i]) ans+=(SolvePhi(a/x,i+1)+prime[i])*f; } return ans; } ll SolveMu(ll a,ll b) { if(a<prime[b])return 0; ll ans = h[Id(a)]+(b-1); for(int i=b;i<=cnt&&prime[i]*prime[i]<=a;i++) { ans-=SolveMu(a/prime[i],i+1); } return ans; } int main() { int t; scanf("%d",&t); while(t--) { scanf("%lld",&n); id=0; cnt=0; if(n==0) { puts("0 0"); continue; } sn = sqrt(n); for(int i=1;i<=n;i=a[id]+1)a[++id]=n/(n/i),g[id]=((a[id]+1)*a[id])/2-1,h[id]=a[id]-1; for(int i=2;i<=sn;i++)if(h[i]!=h[i-1]) { prime[++cnt]=i;sum[cnt]=sum[cnt-1]+i; ll lim = 1ll*i*i; for(int j=id;a[j]>=lim;j--) { g[j]-=i*(g[Id(a[j]/i)]-g[i-1]); h[j]-=(h[Id(a[j]/i)]-h[i-1]); } } for(int i=1;i<=id;i++)g[i]-=h[i],h[i]*=-1; printf("%lld %lld\n",SolvePhi(n,1)+1,SolveMu(n,1)+1); } }
|