You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.8 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
const int N = 1e5 + 50, mod = 1e9 + 7;
bool notPrime[N];
int primes[N], pcnt;
ll g(ll x, ll p)
{
ll xx = x;
if (p == 1) return 1;
ll r = 1;
while (x % r == 0) r = r * p % mod;
if (r / p > 1) printf("g(%lld, %lld)\n", xx, p);
return r / p;
}
ll f(ll x, ll y)
{
ll r = 1;
for (int i = 0; i < pcnt && x >= primes[pcnt]; i++)
if (x % primes[i] == 0)
{
r = r * g(y, primes[i]) % mod;
while (x % primes[i] == 0) x /= primes[i];
}
if (x != 1) r = r * g(y, x) % mod;
return r;
}
ll fpow(ll a, ll b)
{
ll r = 1;
for (; b; b >>= 1, a = a * a % mod)
if (b & 1)
r = r * a % mod;
return r;
}
int main()
{
for (ll i = 2; i < N; i++)
if (!notPrime[i])
for (ll j = (primes[pcnt++] = i, i * i); j < N; j += i)
notPrime[j] = true;
ll x, n;
cin >> x >> n;
ll xx = x;
vector<ll> v;
for (int i = 0; i < pcnt && x >= primes[pcnt]; i++)
if (x % primes[i] == 0)
{
v.push_back(primes[i]);
while (x % primes[i] == 0) x /= primes[i];
}
if (x != 1) v.push_back(x);
x = xx;
ll ans = 1;
for (ll p : v)
{
ll cur = 1, tmp = 1;
while (n / p >= cur)
cur = cur * p, tmp = fpow(p, n / cur) * tmp % mod;
ans = ans * tmp % mod;
}
cout << ans;
return 0;
}