#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #ifdef LOCAL #include "../debug/debug.h" #else #define debug(...) #define debugArr(...) #endif using namespace std; using namespace __gnu_pbds; using ll = long long; using db = long double; using pi = pair<int,int>; using pl = pair<ll,ll>; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; using vpi = vector<pi>; using vpl = vector<pl>; using vvi = vector<vi>; #define mp make_pair #define eb emplace_back #define pb push_back #define x first #define y second #define sz(x) int((x).size()) #define bg(x) begin(x) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i,a,b) for(int i=(a);i<(b);i++) #define per(i,a,b) for(int i=(b)-1;i>=(a);i--) #define ft front() #define bk back() #define rsz resize #define ins insert #define each(a,x) for(auto&a:x) template<class T> bool ckmin(T& a, T b) { return b<a?a=b,1:0; } template<class T> bool ckmax(T& a, T b) { return b>a?a=b,1:0; } template<class T> int lwb(vector<T>& a, const T& b) { return int(lower_bound(all(a),b)-bg(a)); } template<class T> int upb(vector<T>& a, const T& b) { return int(upper_bound(all(a),b)-bg(a)); } template<class T> void remdup(vector<T>& v) { sort(all(v)); v.erase(unique(all(v)),end(v)); } constexpr int pct(int x) { return __builtin_popcount(x); } constexpr int bitlog(int x) { return x == 0 ? 0 : 31 - __builtin_clz(x); } constexpr int pct(ll x) { return __builtin_popcountll(x); } constexpr int bitlog(ll x) { return x == 0 ? 0 : 63 - __builtin_clzll(x); } constexpr ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up constexpr ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } // divide a by b rounded down constexpr int cdiv(int a, int b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded down constexpr int fdiv(int a, int b) { return a / b - ((a ^ b) < 0 && a % b); } // divide a by b rounded down const pi MOVES[] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}}; #ifdef LOCAL mt19937_64 rng(0xabadbeef); #else mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); #endif ll randr(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rng); } const int N = 1e6+32; ll fact[N]; ll finv[N]; ll p; ll fpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % p; a = (a * a) % p; b /= 2; } return res; } ll inv(ll x) { return fpow(x, p - 2); } void init() { fact[0] = 1; rep(i,1,N) fact[i] = (fact[i - 1] * i) % p; finv[N - 1] = inv(fact[N - 1]); per(i,1,N) { finv[i - 1] = (finv[i] * i) % p; } } ll a, b, c; void solve() { if (a == 1) { cout << b << ' ' << 1 << '\n'; return; } if (c == a + b - 1) { debug("Should pass"); } ll x = a * b; ll y = fact[a * b]; rep(i,0,a) { y = (y * fact[i]) % p; y = (y * inv(fact[i + b])) % p; } y = (y * y) % p; cout << x << ' ' << y << '\n'; // cout << (x + y) % p << '\n'; } signed main() { cin.tie(0)->sync_with_stdio(0); cin >> a >> b >> c >> p; init(); solve(); return 0; }
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #ifdef LOCAL #include "../debug/debug.h" #else #define debug(...) #define debugArr(...) #endif using namespace std; using namespace __gnu_pbds; using ll = long long; using db = long double; using pi = pair<int,int>; using pl = pair<ll,ll>; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; using vpi = vector<pi>; using vpl = vector<pl>; using vvi = vector<vi>; #define mp make_pair #define eb emplace_back #define pb push_back #define x first #define y second #define sz(x) int((x).size()) #define bg(x) begin(x) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i,a,b) for(int i=(a);i<(b);i++) #define per(i,a,b) for(int i=(b)-1;i>=(a);i--) #define ft front() #define bk back() #define rsz resize #define ins insert #define each(a,x) for(auto&a:x) template<class T> bool ckmin(T& a, T b) { return b<a?a=b,1:0; } template<class T> bool ckmax(T& a, T b) { return b>a?a=b,1:0; } template<class T> int lwb(vector<T>& a, const T& b) { return int(lower_bound(all(a),b)-bg(a)); } template<class T> int upb(vector<T>& a, const T& b) { return int(upper_bound(all(a),b)-bg(a)); } template<class T> void remdup(vector<T>& v) { sort(all(v)); v.erase(unique(all(v)),end(v)); } constexpr int pct(int x) { return __builtin_popcount(x); } constexpr int bitlog(int x) { return x == 0 ? 0 : 31 - __builtin_clz(x); } constexpr int pct(ll x) { return __builtin_popcountll(x); } constexpr int bitlog(ll x) { return x == 0 ? 0 : 63 - __builtin_clzll(x); } constexpr ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up constexpr ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } // divide a by b rounded down constexpr int cdiv(int a, int b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded down constexpr int fdiv(int a, int b) { return a / b - ((a ^ b) < 0 && a % b); } // divide a by b rounded down const pi MOVES[] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}}; #ifdef LOCAL mt19937_64 rng(0xabadbeef); #else mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); #endif ll randr(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rng); } const int N = 1e6+32; ll fact[N]; ll finv[N]; ll p; ll fpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % p; a = (a * a) % p; b /= 2; } return res; } ll inv(ll x) { return fpow(x, p - 2); } void init() { fact[0] = 1; rep(i,1,N) fact[i] = (fact[i - 1] * i) % p; finv[N - 1] = inv(fact[N - 1]); per(i,1,N) { finv[i - 1] = (finv[i] * i) % p; } } ll a, b, c; void solve() { if (a == 1) { cout << b << ' ' << 1 << '\n'; return; } if (c == a + b - 1) { debug("Should pass"); } ll x = a * b; ll y = fact[a * b]; rep(i,0,a) { y = (y * fact[i]) % p; y = (y * inv(fact[i + b])) % p; } y = (y * y) % p; cout << x << ' ' << y << '\n'; // cout << (x + y) % p << '\n'; } signed main() { cin.tie(0)->sync_with_stdio(0); cin >> a >> b >> c >> p; init(); solve(); return 0; } |