Let's introduce some definitions that will be needed later.
Let prime(x)prime(x) be the set of prime divisors of xx. For example, prime(140)={2,5,7}prime(140)={2,5,7}, prime(169)={13}prime(169)={13}.
Let g(x,p)g(x,p) be the maximum possible integer pkpk where kk is an integer such that xx is divisible by pkpk. For example:
- g(45,3)=9=9 (45 is divisible by 32=9 but not divisible by 33=27),
- g(63,7)=7=7 (63 is divisible by 71=7 but not divisible by 72=49).
Let f(x,y)f(x,y) be the product of g(y,p)g(y,p) for all pp in prime(x)prime(x). For example:
- f(30,70)=g(70,2)⋅g(70,3)⋅g(70,5)=21⋅30⋅51=10,
- f(525,63)=g(63,3)⋅g(63,5)⋅g(63,7)=32⋅50⋅71=63.
You have integers xx and nn. Calculate f(x,1)⋅f(x,2)⋅…⋅f(x,n)mod(10e9+7).
Input
The only line contains integers xx and nn (2≤x≤10e9, 1≤n≤10e18) — the numbers used in formula.
Output
Print the answer.
Examples
input
10 2output
2input
20190929 1605output
363165664input
947 987654321987654321output
593574252Note
In the first example, f(10,1)=g(1,2)⋅g(1,5)=1, f(10,2)=g(2,2)⋅g(2,5)=2.
In the second example, actual value of formula is approximately 1.597⋅10e171. Make sure you print the answer modulo (10e9+7).
In the third example, be careful about overflow issue.
题目大意:
给定一个数x和n,让求 f(x,1)⋅f(x,2)⋅…⋅f(x,n)mod(10e9+7)的值
f(x,n)=g(n,p1)*g(n,p2).......其中px代表的是x的质因数。
g(n,x)=x^i(其中x^i代表能被n整除的最大的值)。
因为数据范围是1e18,所以必定有某种规律。
以一个例子说明 :( 10 10 )
对10分解质因子,发现有两个数,分别为2和5,那么结果表达式为:
结果=f(10,1)*f(10,2).....*f(10,10)
=g(1,2)*g(1,5)........*g(10,2)*g(10,5)。
=2^0*5^0*...........
思考一下,其实对于每一个质因数,应该单独计算从1到n有多少个数字满足条件。
现在我就以2这个质因数为例,1到10中,g(x,2)中2^1出现了几次?2 6 10共3次,2^2出现了几次?4 共1次,2^3出现了几次?8 共1次,但是,4相当于出现了两次2(因为是相乘的运算)。8相当于出现了3次2。
10/2=5 5/2=2 2/2=1.注意观察这三个数字,5+2+1=3+1*2+1*3。
通过这种方法求得一个ans,然后让结果乘上当前素因子的ans次方。
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<cstring>
typedef long long ll;
using namespace std;
ll x,n;
const int maxn=1e5;
const long long mod=1e9+7;
ll phi[maxn];
int p;
void prime(ll x)
{
for(ll i=2; i*i<=x; ++i)
{
if(x%i==0)
{
phi[p++]=i;
while(x%i==0)
x/=i;
}
}
if(x>1)
phi[p++]=x;
//质因数分解完毕~
}
ll pow(ll x,ll y)
{
//x*y%mod;
ll ans=1;
while(y)
{
if(y&1)
ans=(ans*x)%mod;
x=(x*x)%mod;
y/=2;
}
return ans%mod;
}
int main()
{
scanf("%lld%lld",&x,&n);
memset(phi,0,sizeof(phi));
p=0;
prime(x);
for(int i=0;i<p;++i)
printf("%d\n",phi[i]);
long long puts=1;
for(int i=0; i<p; ++i)
{
ll num=n,ans=0;
while(num)
{
ans=ans+(1ll*num/phi[i]);
num/=phi[i];
}
puts=(puts*pow(phi[i],ans))%mod;
}
printf("%lld\n",puts%mod);
return 0;
}