把x分解质因数,枚举因子和指数看出现多少次
#include <iostream>
#include <queue>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL Mod = (LL)1e9+7;
LL p[41622];
LL tot = 0;
void calc(LL n) {
for (LL i = 2; i <= sqrt(n+0.5); i++)
if (n%i == 0) {
p[++tot] = i;
while(n%i == 0) {
n /= i;
}
}
if (n > 1) {
p[++tot] = n;
}
}
LL mul(LL a,LL b){
LL ans = 0;
a = a%Mod;
for ( ; b; b>>=1,a = (a+a)%Mod)
if (b&1) ans = (ans+a)%Mod;
return ans;
}
LL qpow(LL a,LL b) {
LL ans = 1;
for ( ; b; b>>=1,a = mul(a,a))
if (b&1) ans = mul(ans,a);
return ans;
}
int main() {
long long xx,nn;
LL x,n;
cin >> xx >> nn;
x=xx; n = nn;
calc(x);
LL ans = 1;
for (LL i = 1; i <= tot; i++) {
unsigned long long t;
for (unsigned long long j = p[i]; j <= n; j = t) {
if (1.0*n/p[i] < j) {
ans = (ans*qpow(j,n/j))%Mod;
break;
}
t = j*p[i];
ans = (ans*qpow(j,n/j-n/t))%Mod;
}
}
cout << (long long)ans;
return 0;
}
Let’s introduce some definitions that will be needed later.
Let ?????(?) be the set of prime divisors of ?. For example, ?????(140)={2,5,7}, ?????(169)={13}.
Let ?(?,?) be the maximum possible integer ?? where ? is an integer such that ? is divisible by ??. For example:
?(45,3)=9 (45 is divisible by 32=9 but not divisible by 33=27),
?(63,7)=7 (63 is divisible by 71=7 but not divisible by 72=49).
Let ?(?,?) be the product of ?(?,?) for all ? in ?????(?). For example:?(30,70)=?(70,2)⋅?(70,3)⋅?(70,5)=21⋅30⋅51=10,
?(525,63)=?(63,3)⋅?(63,5)⋅?(63,7)=32⋅50⋅71=63.
You have integers ? and ?. Calculate ?(?,1)⋅?(?,2)⋅…⋅?(?,?)mod(109+7).Input
The only line contains integers ? and ? (2≤?≤109, 1≤?≤1018) — the numbers used in formula.Output
Print the answer.Examples
inputCopy
10 2
outputCopy
2