没明白为啥是欧拉函数,先屯着
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll maxn=4e6+5; const ll MAX=1e9; ll P[maxn]; ll phi[maxn]; ll A[maxn]; bool f[maxn]; ll K=0; void init() { phi[1]=1; for(int i=2; i<maxn; i++) { if(!f[i]) { P[K++]=i; phi[i]=i-1; } for(int j=0; j<K&&i*P[j]<maxn; j++) { phi[i*P[j]]=phi[i]*(i%P[j]?P[j]-1:P[j]); f[i*P[j]]=1; if(i%P[j]==0) { break; } } } } int main() { int T; init(); scanf("%d",&T); ll x; ll ans; while(T--) { scanf("%lld",&x); ans=0; ll t=sqrt(x)+1,d; while(t) { ans+=x/(t*t)*phi[t]; t--; } cout<<ans<<' '; } }