#include<iostream> #include<vector> #include<cstring> #include<queue> #include<algorithm> #define maxn 1500010 #define ll long long #define uint unsigned int #define lowbit(i) ((i) & (-i)) usingnamespacestd;
uint n; int p, pp;
ll pow_mod(ll x, ll n){ ll s = 1; for (; n; n >>= 1, x = x * x % p) if (n & 1) s = s * x % p; return s; }
inlineintadd(int x, int y, int p = ::p){ return (x += y) >= p ? x - p : x; }
constint N = 1500000; int pri[maxn], cnt, d[maxn], num[maxn]; bool isp[maxn]; voidinit_isp(int n){ d[1] = 1; for (int i = 2; i <= n; ++i) { if (!isp[i]) pri[++cnt] = i, d[i] = 2, num[i] = 1; for (int j = 1; j <= n && i * pri[j] <= n; ++j) { isp[i * pri[j]] = 1; if (i % pri[j] == 0) { d[i * pri[j]] = d[i] / (num[i] + 1) * (num[i] + 2); num[i * pri[j]] = num[i] + 1; break; } d[i * pri[j]] = d[i] * 2; num[i * pri[j]] = 1; } } for (int i = 1; i <= n; ++i) d[i] += d[i - 1]; }
intcalc_d(uint n){ if (n <= N) return d[n]; int ans = 0; for (uint l = 1, r; l <= n; l = r + 1) { r = n / (n / l); ans = add(ans, 1ll * (r - l + 1) * (n / l) % pp, pp); } return ans; }
cin >> n >> p; pp = p - 1; init_isp(N); ll ans = 1; for (uint l = 1, r; l <= n; l = r + 1) { r = n / (n / l); ll mul = 1ll * l * l % p * pow_mod(1ll * (r + 1) * (r + 1) % p, p - 2) % p; ans = ans * pow_mod(mul, calc_d(n / l)) % p; } cout << ans << "\n"; return0; }