Kyopro Library
 
読み取り中…
検索中…
一致する文字列を見つけられません
modint_dynamic.hpp
[詳解]
1#include"../../kyopro_library/template.hpp"
2
3/// @brief 実行時に mod を変更できる ModInt
5 ll value;
6 static ll mod;
7 static void set_mod(ll x) { mod=x; }
8 static ll get_mod() { return mod; }
9 ModIntDynamic(ll x=0) {
10 if(x>=0) value=x%mod;
11 else value=mod-(-x)%mod;
12 }
14 ModIntDynamic operator+() const { return ModIntDynamic(*this); }
16 value+=other.value;
17 if(value>=mod) value-=mod;
18 return*this;
19 }
21 value+=mod-other.value;
22 if(value>=mod) value-=mod;
23 return*this;
24 }
26 value=value*other.value%mod;
27 return*this;
28 }
30 (*this)*=other.inv();
31 return*this;
32 }
33 ModIntDynamic operator+(const ModIntDynamic& other) const { return ModIntDynamic(*this)+=other; }
34 ModIntDynamic operator-(const ModIntDynamic& other) const { return ModIntDynamic(*this)-=other; }
35 ModIntDynamic operator*(const ModIntDynamic& other) const { return ModIntDynamic(*this)*=other; }
36 ModIntDynamic operator/(const ModIntDynamic& other) const { return ModIntDynamic(*this)/=other; }
37 ModIntDynamic pow(ll x) const {
39 while(x) {
40 if(x&1) ret*=mul;
41 mul*=mul;
42 x>>=1;
43 }
44 return ret;
45 }
46 ModIntDynamic inv() const { return pow(mod-2); }
47 bool operator==(const ModIntDynamic& other) const { return value==other.value; }
48 bool operator!=(const ModIntDynamic& other) const { return value!=other.value; }
49 friend ostream& operator<<(ostream& os, const ModIntDynamic& x) { return os<<x.value; }
50 friend istream& operator>>(istream& is, ModIntDynamic& x) {
51 ll v;
52 is>>v;
54 return is;
55 }
56};
57ll ModIntDynamic::mod=998244353;
実行時に mod を変更できる ModInt
ModIntDynamic & operator-=(const ModIntDynamic &other)
friend ostream & operator<<(ostream &os, const ModIntDynamic &x)
ModIntDynamic & operator*=(const ModIntDynamic other)
ModIntDynamic operator+() const
friend istream & operator>>(istream &is, ModIntDynamic &x)
static ll get_mod()
ModIntDynamic(ll x=0)
bool operator==(const ModIntDynamic &other) const
ModIntDynamic operator+(const ModIntDynamic &other) const
ModIntDynamic operator*(const ModIntDynamic &other) const
ModIntDynamic pow(ll x) const
ModIntDynamic operator-(const ModIntDynamic &other) const
static void set_mod(ll x)
ModIntDynamic operator-() const
ModIntDynamic & operator+=(const ModIntDynamic &other)
ModIntDynamic inv() const
ModIntDynamic & operator/=(ModIntDynamic other)
ModIntDynamic operator/(const ModIntDynamic &other) const
bool operator!=(const ModIntDynamic &other) const