#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long double LD; typedef long long LL; typedef unsigned long long ULL; using namespace std; int main() { #ifdef DEBUG freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif LL n; int m; cin >> n >> m; int y = 1; int ans = 0; for (LL i = n; i >= max(0LL, n - m); --i) { int d = (i & 1) ? (-1) : (+1); int add = y * d; if (add < 0) add += m; ans += add; if (ans >= m) ans -= m; y = ((LL)y * i) % m; } cout << ((LL)ans * ans) % m << '\n'; return 0; }