显然ans=Σ[d|n]d*F(n/d)/d=nΣF(d)
F(n)为n以内与n互质的数之和
F(n)=n*phi(n)/2 由互质的对称性[ gcd(i,n)==1 <=> gcd(n-i,n) ] 可知
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
inline char nc()
{
static char buf[100000],*p1=buf,*p2=buf;
if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
return *p1++;
}
inline void read(int &x){
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
const int maxn=1000000;
int prime[maxn+5],num;
int phi[maxn+5];
int vst[maxn+5];
inline void Pre()
{
phi[1]=1;
for (int i=2;i<=maxn;i++)
{
if (!vst[i])
prime[++num]=i,phi[i]=i-1;
for (int j=1;i*prime[j]<=maxn;j++)
{
vst[i*prime[j]]=1;
if (i%prime[j]==0)
{
phi[i*prime[j]]=prime[j]*phi[i];
break;
}
else
phi[i*prime[j]]=phi[i]*phi[prime[j]];
}
}
}
inline ll F(int i){
if (i==1) return 1LL;
return (ll)phi[i]*i>>1;
}
int main()
{
ll ret=0;
int n,Q;
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
Pre();
read(Q);
while (Q--)
{
ret=0;
read(n);
int i;
for (i=1;i*i<n;i++)
if (n%i==0)
ret+=F(i),ret+=F(n/i);
if (i*i==n)
ret+=F(i);
printf("%lld\n",ret*n);
}
return 0;
}