#include <cstdio>
#include <cmath>
#define ll long long
#define rll register ll
using namespace std;
const int mod = 999911658, su[5] = {0, 2, 3, 4679, 35617};
ll a[5], b[5], jc[5][36000], X, Y, n, g, ans, ans2 = 1;
inline ll pow(rll x, rll y, rll mo) {
x %= mo;
rll sum = 1;
while (y > 0) {
if (y & 1)
sum = sum * x % mo;
x = x * x % mo;
y /= 2;
}
return sum;
}
inline ll zh(rll x, rll y, rll mo, rll u) {
if (x < y)
return 0;
return jc[u][x] * pow(jc[u][y], mo - 2, mo) % mo * pow(jc[u][x - y], mo - 2, mo) % mo;
}
inline ll lcs(rll x, rll y, rll mo, rll u) {
if (y == 0)
return 1;
return zh(x % mo, y % mo, mo, u) * lcs(x / mo, y / mo, mo, u) % mo;
}
inline ll crt(rll x) {
rll sum = 0;
for (rll i = 1; i < 5; i++) {
rll y = lcs(n, x, su[i], i);
sum = (sum + y * a[i] * b[i] % mod) % mod;
}
return (sum + mod) % mod;
}
inline void exgcd(rll w1, rll w2) {
if (w2 == 0) {
X = 1;
Y = 0;
return;
}
exgcd(w2, w1 % w2);
rll U = X;
X = Y;
Y = U - w1 / w2 * Y;
}
int main() {
for (rll i = 1; i < 5; i++) {
a[i] = mod / su[i];
exgcd(a[i], su[i]);
b[i] = X;
jc[i][0] = 1;
for (rll j = 1; j <= su[i]; j++)
jc[i][j] = jc[i][j - 1] * j % su[i];
}
scanf("%lld%lld", &n, &g);
for (rll i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
ans = (ans + crt(i)) % mod;
if (i != n / i && n % (n / i) == 0)
ans = (ans + crt(n / i)) % mod;
}
}
printf("%lld", pow(g, ans, mod + 1));
}
一本通1651:【例 4】古代猪文
最新推荐文章于 2024-08-26 00:02:00 发布