Skip to content

Commit 089726a

Browse files
authored
split up mod in division (#93)
1 parent f0fcae7 commit 089726a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

library/math/mod_int.hpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,5 @@ struct mint {
88
mint operator+(mint b) { return x - mod + b.x; }
99
mint operator-(mint b) { return x - b.x; }
1010
mint operator*(mint b) { return ll(x) * b.x % mod; }
11-
mint operator/(mint b) {
12-
int m = mod, u = 1, v = 0;
13-
while (m)
14-
u = exchange(v, u - b.x / m * v),
15-
b.x = exchange(m, b.x % m);
16-
assert(b.x == 1);
17-
return *this * u;
18-
}
11+
#include "mod_int_division.hpp"
1912
};

library/math/mod_int_division.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
mint operator/(mint b) {
3+
int m = mod, u = 1, v = 0;
4+
while (m)
5+
u = exchange(v, u - b.x / m * v),
6+
b.x = exchange(m, b.x % m);
7+
assert(b.x == 1);
8+
return *this * u;
9+
}

0 commit comments

Comments
 (0)