File tree Expand file tree Collapse file tree 1 file changed +32
-8
lines changed Expand file tree Collapse file tree 1 file changed +32
-8
lines changed Original file line number Diff line number Diff line change 1
1
#include < bits/stdc++.h>
2
- #define ll long long
2
+ #define LL long long
3
3
using namespace std ;
4
- const ll N= 1e6 +7 ,mod= 998244353 ;
5
- ll inv[N];
4
+ const LL N = 1e6 +7 , mod = 998244353 ;
5
+ LL inv[N];
6
6
7
- int main ()
8
- {
7
+ /* ********************************/
8
+ // Linear method to compute inv[i]
9
+ void main ()
10
+ {
9
11
int i;
10
12
for (inv[1 ]=1 ,i=2 ;i<N;++i)
11
- inv[i]=(mod-mod/i)* inv[mod%i]% mod;
13
+ inv[i]=(mod-mod/i) * inv[mod%i] % mod;
12
14
13
- // ....
15
+ ret = ret* inv[n] % mod; // ret = (ret / n) % mod;
16
+ }
14
17
15
- ret = ret* inv[n]%mod; // ret = (ret / n) % M;
18
+ /* ********************************/
19
+ // Qucik Pow
20
+
21
+ LL quickPow (int x, int y)
22
+ {
23
+ LL ret = 1 ;
24
+ LL cur = x;
25
+ while (y)
26
+ {
27
+ if (y & 1 )
28
+ {
29
+ ret = (LL)ret * cur % mod;
30
+ }
31
+ cur = (LL)cur * cur % mod;
32
+ y >>= 1 ;
33
+ }
34
+ return ret;
35
+ }
36
+
37
+ LL inv (LL x)
38
+ {
39
+ return quickPow (x, mod - 2 );
16
40
}
You can’t perform that action at this time.
0 commit comments