#include <iostream>
using namespace std;
typedef long long ll;
// Function to compute factorial modulo M
ll factorial_mod(ll n, ll M) {
ll res = 1;
for (ll i = 2; i <= n; ++i)
res = (res * i) % M;
return res;
}
// Function to compute power modulo M
ll power_mod(ll base, ll exponent, ll M) {
ll result = 1;
base = base % M;
while (exponent > 0) {
if (exponent % 2 == 1)
result = (result * base) % M;
base = (base * base) % M;
exponent = exponent / 2;
}
return result;
}
// Function to compute modular inverse using Fermat's Little Theorem
ll mod_inverse(ll a, ll M) {
return power_mod(a, M - 2, M);
}
int main() {
ll N, M;
cin >> N >> M;
ll N_factorial = factorial_mod(N, M);
cout<<N_factorial<<endl;
ll numerator = (N_factorial * ((N * N - 1) % M)) % M;
ll denominator = (4 * N) % M;
// Compute modular inverse of denominator
ll denom_inv = mod_inverse(denominator, M);
ll S = (numerator * denom_inv) % M;
cout << S << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIGxsOwoKLy8gRnVuY3Rpb24gdG8gY29tcHV0ZSBmYWN0b3JpYWwgbW9kdWxvIE0KbGwgZmFjdG9yaWFsX21vZChsbCBuLCBsbCBNKSB7CiAgICBsbCByZXMgPSAxOwogICAgZm9yIChsbCBpID0gMjsgaSA8PSBuOyArK2kpCiAgICAgICAgcmVzID0gKHJlcyAqIGkpICUgTTsKICAgIHJldHVybiByZXM7Cn0KCi8vIEZ1bmN0aW9uIHRvIGNvbXB1dGUgcG93ZXIgbW9kdWxvIE0KbGwgcG93ZXJfbW9kKGxsIGJhc2UsIGxsIGV4cG9uZW50LCBsbCBNKSB7CiAgICBsbCByZXN1bHQgPSAxOwogICAgYmFzZSA9IGJhc2UgJSBNOwogICAgd2hpbGUgKGV4cG9uZW50ID4gMCkgewogICAgICAgIGlmIChleHBvbmVudCAlIDIgPT0gMSkKICAgICAgICAgICAgcmVzdWx0ID0gKHJlc3VsdCAqIGJhc2UpICUgTT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