Skip to content

Commit d9ddbbb

Browse files
authored
Update Inverse_Element.cpp
1 parent b2c82fc commit d9ddbbb

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed
Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,40 @@
11
#include<bits/stdc++.h>
2-
#define ll long long
2+
#define LL long long
33
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];
66

7-
int main()
8-
{
7+
/*********************************/
8+
// Linear method to compute inv[i]
9+
void main()
10+
{
911
int i;
1012
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;
1214

13-
// ....
15+
ret = ret* inv[n] % mod; // ret = (ret / n) % mod;
16+
}
1417

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);
1640
}

0 commit comments

Comments
 (0)