-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf439.cpp
More file actions
executable file
·123 lines (120 loc) · 3.04 KB
/
cf439.cpp
File metadata and controls
executable file
·123 lines (120 loc) · 3.04 KB
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Debug(x) cout << "> " << #x << " : " << x << "\n";
#define DebugArr(a,n) For(i,0,n) cout << i << " : " << a[i] << "\n";
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define ForD(i,a,b) for(int i=(a);i>(b);i--)
#define tests int t; cin>>t; while(t--)
#define Imax INT_MAX
#define Imin INT_MIN
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define sz(a) int((a).size())
#define pb push_back
#define it iterator
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mod 1000000007
/////////////////////////////////////////////////////////////////////
long long degree(long long a, long long k, long long p) {
long long res = 1;
long long cur = a;
while (k) {
if (k%2) {
res = (res * cur)%p;
}
k /= 2;
cur = (cur * cur) % p;
}
return res;
}
int get_degree(long long n, long long p) { // returns the degree with which p is in n!
int degree_num = 0;
long long u = p;
long long temp = n;
while (u <= temp) {
degree_num += temp/u;
u *= p;
}
return degree_num;
}
long long combinations(int n, int k, long long p) {
int num_degree = get_degree(n,p) - get_degree(n- k,p);
int den_degree = get_degree(k,p);
if (num_degree > den_degree) {
return 0;
}
long long res = 1;
for (long long i = n; i > n- k; --i) {
long long ti = i;
while(ti % p == 0) {
ti /= p;
}
res = (res *ti)%p;
}
for (long long i = 1; i <= k; ++i) {
long long ti = i;
while(ti % p == 0) {
ti /= p;
}
res = (res * degree(ti, p-2, p))%p;
}
return res;
}
int main()
{//remember to do ifs and modulo p
int array[3];
long long int p = 998244353;
For(i,0,3) cin >> array[i];
sort(array,array+3);
int a,b,c;
a = array[0];//smallest
b = array[1];
c = array[2];//largest
long long int ans=1,sum=0,tans=0;
//a and b
tans=0;
For(i,0,a+1){
sum = combinations(a,i,p);
For(j,0,a-i){
sum *= (b - j);
if(sum > p) sum = sum%p;
}
tans += sum;
if(tans > p) tans = tans%p;
//Debug(sum)
}
ans *= tans;
ans = ans%p;
//now for a and c
tans=0;
For(i,0,a+1){
sum = combinations(a,i,p);
For(j,0,a-i){
sum *= (c - j);
if(sum > p) sum = sum%p;
}
tans += sum;
if(tans > p) tans = tans%p;//Debug(sum)
}ans *= tans;
ans = ans%p;
//for b and c
tans=0;
For(i,0,b+1){
sum = combinations(b,i,p);
For(j,0,b-i){
sum *= (c - j);
if(sum > p) sum = sum%p;
}
tans += sum;
if(tans > p) tans = tans%p;//Debug(sum)
}
ans *= tans;
ans = ans%p;
cout << ans;
return 0;
}