题目大意
给定 ,求
Solution
根据欧拉函数的性质,我们知道 ,那么我们考虑把和式里的 拆开
考虑交换求和顺序,把 提前
把 提出来
我们发现后面的三个和式可以拆成三个不相关的和式
我们发现前面的欧拉函数可以预处理,后面的式子也能预处理,而且后面是一个整除分块的样子,那么预处理整除分块就行了。
时间复杂度 。
std
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lll __int128
#define ld long double
#define pb push_back
#define mk make_pair
#define ppcnt __builtin_popcount
#define sort stable_sort
ull read()
{
ull k=0;
char c=getchar();
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
return k;
}
int prime[10000010],cnt=0;
bool vis[50000010];
ull phi[50000010];
void init()
{
phi[1]=1;
for(int i=2;i<=50000000;++i)
{
if(!vis[i])
{
phi[i]=i-1;
prime[++cnt]=i;
}
for(int j=1;j<=cnt&&i*prime[j]<=50000000;++j)
{
vis[prime[j]*i]=1;
phi[prime[j]*i]=phi[i]*phi[prime[j]];
if(i%prime[j]==0)
{
phi[prime[j]*i]=phi[i]*prime[j];
break;
}
}
}
for(ull i=1;i<=50000000;++i)phi[i]*=i*i*i;
for(int i=1;i<=50000000;++i)phi[i]+=phi[i-1];
}
void solve()
{
ull n=read();
int l=1,r;
ull ans=0;
while(l<=n)
{
r=n/(n/l);
ull s=n/l;
s=(s*(s+1))>>1;
s=s*s*s;
ans+=s*(phi[r]-phi[l-1]);
l=r+1;
}
cout<<ans<<"\n";
}
int main()
{
std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
init();
int T=read();
while(T--)solve();
return 0;
}