File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments