#include "bits/stdc++.h"
using namespace std;
#define rep(i, b, e) for (int i = (b); i <= (e); i++)
#define per(i, b, e) for (int i = (e); i >= (b); i--)
#define FOR(i, b, e) rep(i, b, (e)-1)
#define SZ(x) int(x.size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
auto& operator<<(auto& o, pair<auto, auto> p) {
return o << "(" << p.st << ", " << p.nd << ")";
}
auto operator<<(auto& o, auto x) -> decltype(end(x), o) {
o << "{";
int i = 0;
for (auto e : x)
o << ", " + 2 * !i++ << e;
return o << "}";
}
#ifdef LOCAL
#define deb(x...) \
cerr << "[" #x "]: ", [](auto... $) { \
((cerr << $ << "; "), ...) << endl; \
}(x)
#else
#define deb(...)
#endif
ll fast_pow(ll a, int w, const int m) {
if (w == 0)
return 1;
if (w == 1)
return a % m;
ll p = fast_pow(a, w / 2, m);
p = (p * p) % m;
if (w % 2 == 1)
p = (p * a) % m;
return p;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
int a, b, c, pp;
cin >> a >> b >> c >> pp;
const int p = pp;
int ans = a * b;
ll res = 1;
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
res *= ((a - i) + (b - j) - 1);
res %= pp;
}
}
ll inv = fast_pow(res, p - 2, p);
ll sil = 1;
for (ll i = 1; i <= a * b; i++) {
sil *= i;
sil %= p;
}
ll rozw = (sil * inv) % p;
rozw = (rozw * rozw) % p;
cout << ans << " " << rozw << "\n";
cerr << (ans + rozw) % p << "\n";
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #include "bits/stdc++.h" using namespace std; #define rep(i, b, e) for (int i = (b); i <= (e); i++) #define per(i, b, e) for (int i = (e); i >= (b); i--) #define FOR(i, b, e) rep(i, b, (e)-1) #define SZ(x) int(x.size()) #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define st first #define nd second using ll = long long; using vi = vector<int>; using pii = pair<int, int>; auto& operator<<(auto& o, pair<auto, auto> p) { return o << "(" << p.st << ", " << p.nd << ")"; } auto operator<<(auto& o, auto x) -> decltype(end(x), o) { o << "{"; int i = 0; for (auto e : x) o << ", " + 2 * !i++ << e; return o << "}"; } #ifdef LOCAL #define deb(x...) \ cerr << "[" #x "]: ", [](auto... $) { \ ((cerr << $ << "; "), ...) << endl; \ }(x) #else #define deb(...) #endif ll fast_pow(ll a, int w, const int m) { if (w == 0) return 1; if (w == 1) return a % m; ll p = fast_pow(a, w / 2, m); p = (p * p) % m; if (w % 2 == 1) p = (p * a) % m; return p; } int main() { ios_base::sync_with_stdio(false); cin.tie(); int a, b, c, pp; cin >> a >> b >> c >> pp; const int p = pp; int ans = a * b; ll res = 1; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { res *= ((a - i) + (b - j) - 1); res %= pp; } } ll inv = fast_pow(res, p - 2, p); ll sil = 1; for (ll i = 1; i <= a * b; i++) { sil *= i; sil %= p; } ll rozw = (sil * inv) % p; rozw = (rozw * rozw) % p; cout << ans << " " << rozw << "\n"; cerr << (ans + rozw) % p << "\n"; } |
English