Skip to content

Commit 0667f64

Browse files
committed
fix: CE on luogu
1 parent 0854309 commit 0667f64

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/alfred/math/mod-int.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ class ModInt {
2020
value_type v;
2121
constexpr ModInt(void) noexcept : v(0) {}
2222
template <class T, is_signed_int_t<T> *_ = nullptr>
23-
constexpr ModInt(T _v) {
24-
int64_t x = (int64_t)(_v % (int64_t)(mod()));
25-
if (x < 0) x += mod();
26-
v = (uint32_t)(x);
27-
}
23+
constexpr ModInt(T _v) : v(value_type(norm(_v))) {}
2824
template <class T, is_unsigned_int_t<T> *_ = nullptr>
29-
constexpr ModInt(T _v) { v = (uint32_t)(_v % mod()); }
25+
constexpr ModInt(T _v) : v(value_type(_v % M)) {}
3026
constexpr value_type val() const noexcept { return v; }
27+
constexpr value_type norm(int64_t v) {
28+
v %= M;
29+
if (v < 0) v += M;
30+
return v;
31+
}
3132
constexpr ModInt operator+() const noexcept { return *this; }
3233
constexpr ModInt operator-() const noexcept { return ModInt(v ? M - v : 0); }
3334
constexpr ModInt &operator+=(const ModInt &rhs) noexcept {

0 commit comments

Comments
 (0)