#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
int phi(int x)
{
int res=1;
for(ll i=2;i*i<=x;i++)
{
if(x%i==0)
{
x/=i;
res*=i-1;
while(x%i==0)
{
x/=i;
res*=i;
}
}
}
if(x>1)
res*=x-1;
return res;
}
ll quickmod(ll a,ll p,ll m)
{
ll ans=1;
while(p)
{
if(p&1)
{
ans=(ans*a)%m;
}
a=(a*a)%m;
p>>=1;
}
return ans%m;
}
int main()
{
int t;
ll n;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
ll ans=0;
for(int i=1;i*i<=n;i++)
{
if(n%i==0)
{
if(i%2)
ans=(ans+quickmod(2,n/i,mod)*phi(i)%mod)%mod;
if(i*i!=n&&(n/i)%2!=0)
ans=(ans+quickmod(2,i,mod)*phi(n/i)%mod)%mod;
}
}
ans=((ans*quickmod(n,mod-2,mod))%mod+mod)%mod;
printf("%lld\n",ans);
}
return 0;
}
HDU 3970
最新推荐文章于 2021-03-18 07:10:36 发布