您的位置:首页 > 其它

Number Theory (Easy) SPOJ - NUMTRYE(数论)(结论类)

2017-10-18 12:42 567 查看
f(n) and g(n) are two functions defined as following :

f(n)=∏(pi2ei+1+1), where pi is prime factor of n and ei is highest power of pi in n.

g(n)=Σ(ngcd(n,i)); 1 <= i <= n

For a given value of n, you have to compute f(n)/g(n) % 1000000007.

Input

First line has T ( <= 10000 ), next T lines has 2 <= n <= 10^12.

Output

f(n)/g(n) % 1000000007 for each test case.

Example

Input:

2

2

4

Output:

3

3

这个怎么说呢,一个结论吧,记住吧,但是不会证明

g(n)=∏p2ei+1i+1pi+1

所以f(n)g(n)=∏pi+1

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#define N 1000500
#define mod 1000000007
using namespace std;
typedef long long  ll;
bool tag
;
vector<int> prime;
void getPrime()
{
for(int i=2;i<N;i++)
if(!tag[i])
{
prime.push_back(i);
for(int j=i+i;j<N;j+=i)
tag[j]=true;
}
}
ll fac[100];
int  k;
int getFac(ll x)
{
k=0;
for(int i=0;(ll)prime[i]*prime[i]<=x;i++)
{
if(x%prime[i]==0)
{
fac[k++]=prime[i];
while(x%prime[i]==0)
x/=prime[i];
}
}
if(x>1)
fac[k++]=x;

}
ll solve()
{
ll ans=1;
for(int i=0;i<k;i++)
ans=ans*(fac[i]+1)%mod;
return ans;
}
int main()
{
getPrime();
int t;
ll n;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
getFac(n);
printf("%lld\n",solve());
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: