#include<iostream> #define maxn 1500010 #define ll long long usingnamespacestd;
int p; inlineintadd(int x, int y){ return (x += y) >= p ? x - p : x; } inlineintmul(int x, int y){ return1ll * x * y % p; } inlineintadd(initializer_list<int> lst){ int s = 0; for (auto t : lst) s = add(s, t); return s; } inlineintmul(initializer_list<int> lst){ int s = 1; for (auto t : lst) s = mul(s, t); return s; } intpow_mod(int x, int n){ int s = 1; for (; n; n >>= 1, x = mul(x, x)) if (n & 1) s = mul(s, x); return s; }
int pri[maxn], cnt, mu[maxn]; bool isp[maxn]; voidinit_isp(int n){ mu[1] = 1; for (int i = 2; i <= n; ++i) { if (!isp[i]) pri[++cnt] = i, mu[i] = -1; for (int j = 1; j <= cnt && i * pri[j] <= n; ++j) { isp[i * pri[j]] = 1; if (i % pri[j] == 0) break; mu[i * pri[j]] = -mu[i]; } } }
intf(int a, int n){ if (n == 0) return1; if (n & 1) return mul(f(a, n / 2), 1 + pow_mod(a, n / 2 + 1)); elsereturn add(mul(f(a, n / 2 - 1), 1 + pow_mod(a, n / 2 + 1)), pow_mod(a, n / 2)); }
int n;
voidwork(){ cin >> n >> p; int ans = 0; for (int i = 1; i <= n; ++i) { int d = pow_mod(i, i), D = 1; for (int j = 1; j <= n / i; ++j) { D = mul(D, d); if (!mu[j]) continue; int _mu = mu[j] < 0 ? p - 1 : 1, t = f(D, n / (i * j)) - 1; ans = add(ans, mul({ _mu, t, t })); } } cout << ans << "\n"; }