#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);
ll numerator = (N_factorial * ((N * N - 1) % M)) % M;
ll denominator = (4 * N) % M;
cout<<denominator<<endl;
// Compute modular inverse of denominator
ll denom_inv = mod_inverse(denominator, M);
ll S = (numerator * denom_inv) % M;
cout << S << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIGxsOwoKLy8gRnVuY3Rpb24gdG8gY29tcHV0ZSBmYWN0b3JpYWwgbW9kdWxvIE0KbGwgZmFjdG9yaWFsX21vZChsbCBuLCBsbCBNKSB7CiAgICBsbCByZXMgPSAxOwogICAgZm9yIChsbCBpID0gMjsgaSA8PSBuOyArK2kpCiAgICAgICAgcmVzID0gKHJlcyAqIGkpICUgTTsKICAgIHJldHVybiByZXM7Cn0KCi8vIEZ1bmN0aW9uIHRvIGNvbXB1dGUgcG93ZXIgbW9kdWxvIE0KbGwgcG93ZXJfbW9kKGxsIGJhc2UsIGxsIGV4cG9uZW50LCBsbCBNKSB7CiAgICBsbCByZXN1bHQgPSAxOwogICAgYmFzZSA9IGJhc2UgJSBNOwogICAgd2hpbGUgKGV4cG9uZW50ID4gMCkgewogICAgICAgIGlmIChleHBvbmVudCAlIDIgPT0gMSkKICAgICAgICAgICAgcmVzdWx0ID0gKHJlc3VsdCAqIGJhc2UpICUgTTsK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