-
Notifications
You must be signed in to change notification settings - Fork 185
/
c.cc
45 lines (42 loc) · 814 Bytes
/
c.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// https://codeforces.com/contest/1228/problem/C
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
ll M = 1000000007;
ll pow(ll a, ll b, ll m) {
ll r = 1, e = a;
while (b) {
if (b & 1) (r *= e) %= m;
(e *= e) %= m;
b >>= 1;
}
return r;
}
int main() {
ll x, n;
cin >> x >> n;
vi p;
if (!(x % 2)) p.push_back(2);
while (x > 1 && !(x % 2)) x /= 2;
for (ll i = 3; i * i <= x; i += 2) {
if (x > 1 && !(x % i)) {
while (!(x % i)) x /= i;
p.push_back(i);
}
}
if (x > 1) p.push_back(x);
ll r = 1;
for (ll a : p) {
ll b = a;
ll c = 0;
while (b <= n) {
c += n / b;
if (LLONG_MAX / b < a) break;
b *= a;
}
(r *= pow(a, c, M)) %= M;
}
cout << r << endl;
}