MCPcopy Create free account
hub / github.com/atcoder/ac-library / dynamic_modint

Class dynamic_modint

atcoder/modint.hpp:141–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139};
140
141template <int id> struct dynamic_modint : internal::modint_base {
142 using mint = dynamic_modint;
143
144 public:
145 static int mod() { return (int)(bt.umod()); }
146 static void set_mod(int m) {
147 assert(1 <= m);
148 bt = internal::barrett(m);
149 }
150 static mint raw(int v) {
151 mint x;
152 x._v = v;
153 return x;
154 }
155
156 dynamic_modint() : _v(0) {}
157 template <class T, internal::is_signed_int_t<T>* = nullptr>
158 dynamic_modint(T v) {
159 long long x = (long long)(v % (long long)(mod()));
160 if (x < 0) x += mod();
161 _v = (unsigned int)(x);
162 }
163 template <class T, internal::is_unsigned_int_t<T>* = nullptr>
164 dynamic_modint(T v) {
165 _v = (unsigned int)(v % mod());
166 }
167
168 int val() const { return _v; }
169
170 mint& operator++() {
171 _v++;
172 if (_v == umod()) _v = 0;
173 return *this;
174 }
175 mint& operator--() {
176 if (_v == 0) _v = umod();
177 _v--;
178 return *this;
179 }
180 mint operator++(int) {
181 mint result = *this;
182 ++*this;
183 return result;
184 }
185 mint operator--(int) {
186 mint result = *this;
187 --*this;
188 return result;
189 }
190
191 mint& operator+=(const mint& rhs) {
192 _v += rhs._v;
193 if (_v >= umod()) _v -= umod();
194 return *this;
195 }
196 mint& operator-=(const mint& rhs) {
197 _v += mod() - rhs._v;
198 if (_v >= umod()) _v -= umod();

Callers

nothing calls this directly

Calls 2

mulMethod · 0.80
invMethod · 0.45

Tested by

no test coverage detected