On Mars, there is a huge company called ACM (A huge Company on Mars), and it’s owned by a younger boss.
Due to no moons around Mars, the employees can only get the salaries per-year. There are n employees in ACM, and it’s time for them to get salaries from their boss. All employees are numbered from 1 to n. With the unknown reasons, if the employee’s work number is k, he can get k^4 Mars dollars this year. So the employees working for the ACM are very rich.
Because the number of employees is so large that the boss of ACM must distribute too much money, he wants to fire the people whose work number is co-prime with n next year. Now the boss wants to know how much he will save after the dismissal.
Input
The first line contains an integer T indicating the number of test cases. (1 ≤ T ≤ 1000) Each test case, there is only one integer n, indicating the number of employees in ACM. (1 ≤ n ≤ 10^8)
Output
For each test case, output an integer indicating the money the boss can save. Because the answer is so large, please module the answer with 1,000,000,007.
Sample Input
2 4 5
Sample Output
82 354
Hint
Case1: sum=1+3*3*3*3=82
Case2: sum=1+2*2*2*2+3*3*3*3+4*4*4*4=354
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define bignum long long
const bignum mod=1000000007;
bignum exgcd(bignum a,bignum b,bignum& x,bignum& y)
{
if(b==0) return x=1,y=0,a;
bignum r=exgcd(b,a%b,x,y);
bignum t=x;
x=y;
y=t-(a/b)*y;
return r;
}
bignum calc(bignum a,bignum b,bignum mod)
{
bignum x,y;
bignum r=exgcd(b,mod,x,y);
x*=a;
x=(x%mod+mod)%mod;
return x;
}
bignum inv2,inv3,inv5;
void init()
{
inv2=calc(1,2,mod);
inv3=calc(1,3,mod);
inv5=calc(1,5,mod);
}
bignum _pow(bignum n,int p)
{
bignum cnt=1;
for(int i=0;i<p;i++)
{
cnt=(cnt*n)%mod;
}
return cnt;
}
bignum sigma_4(bignum n)
{
bignum cnt=_pow(n+1,5)-1;
bignum tmp=5*n%mod*n%mod*(n+1)%mod*(n+1)%mod*inv2%mod;
tmp+=5*n%mod*(n+1)%mod*(n+n+1)%mod*inv3%mod;
tmp%=mod;
tmp+=5*n%mod*(n+1)%mod*inv2%mod;
tmp%=mod;
tmp+=n;
tmp%=mod;
cnt=((cnt-tmp)%mod+mod)%mod;
return cnt*inv5%mod;
}
const int maxn=11000;
int flag[maxn],prime[maxn],pl;
void _prime()
{
for(int i=2;i<maxn;i++)
{
if(flag[i]==0) prime[pl++]=i;
for(int j=0;j<pl&&i*prime[j]<maxn;j++)
{
flag[i*prime[j]]=1;
if(i%prime[j]==0) break;
}
}
}
int fac[maxn],facn;
void _fac(int n)
{
facn=0;
for(int i=0;i<pl&&prime[i]*prime[i]<=n;i++)
{
if(n%prime[i]==0)
{
fac[facn++]=prime[i];
while(n%prime[i]==0) n/=prime[i];
}
}
if(n>1) fac[facn++]=n;
}
int main()
{
init();
_prime();
int ci;scanf("%d",&ci);
while(ci--)
{
int n;scanf("%d",&n);
_fac(n);
int ans=sigma_4((bignum)n);
for(int i=1;i<(1<<facn);i++)
{
int flag=0;
int cnt=1;
for(int j=0;j<facn;j++)
{
if(i&(1<<j))
{
flag++;cnt*=fac[j];
}
}
int tmp=sigma_4((bignum)n/cnt)*_pow(cnt,4)%mod;
if(flag&1) ans-=tmp;
else ans+=tmp;
ans=(ans%mod+mod)%mod;
}
printf("%d\n",ans);
}
return 0;
}