Skip to content

Commit 32fc223

Browse files
committed
add single function for mod division
1 parent 1c6156f commit 32fc223

File tree

5 files changed

+29
-33
lines changed

5 files changed

+29
-33
lines changed

library/math/mod_division.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
const int mod = 998244353;
3+
int mod_div(int x, int y) {
4+
int m = mod, u = 1, v = 0;
5+
while (m) swap(u -= y / m * v, v), swap(y %= m, m);
6+
assert(y == 1);
7+
return 1LL * x * (u + mod) % mod;
8+
}

library/math/mod_int.hpp

Lines changed: 0 additions & 12 deletions
This file was deleted.

library/math/mod_int_division.hpp

Lines changed: 0 additions & 9 deletions
This file was deleted.

library/math/mod_int_pow.hpp

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#define PROBLEM \
2+
"https://onlinejudge.u-aizu.ac.jp/problems/ITP1_1_A"
3+
#include "../template.hpp"
4+
#define const ;
5+
#include "../../../library/math/mod_division.hpp"
6+
#undef const
7+
int main() {
8+
cin.tie(0)->sync_with_stdio(0);
9+
for (mod = 1; mod < 500; mod++) {
10+
for (int x = 0; x < mod; x++) {
11+
for (int y = 0; y < mod; y++) {
12+
if (gcd(y, mod) == 1) {
13+
int quotient = mod_div(x, y);
14+
assert(1LL * quotient * y % mod == x);
15+
}
16+
}
17+
}
18+
}
19+
cout << "Hello World\n";
20+
return 0;
21+
}

0 commit comments

Comments
 (0)