namespace hezlik{
template<class T,class T2,std::ptrdiff_t id>
class dynamic_modint{
public:
using type=T;
using type2=T2;
using identity_type=std::ptrdiff_t;
private:
using mint=dynamic_modint;
protected:
static type mod;
public:
static void set_mod(const type &_mod){mod=_mod;}
static type umod(){return mod;}
protected:
type v;
public:
dynamic_modint():v(){};
dynamic_modint(const type &other):v(other){}
dynamic_modint(type &&other):v(other){}
dynamic_modint &operator = (const type &other){v=other;return *this;}
dynamic_modint &operator = (type &&other){v=other;return *this;}
template<class input_type>
static mint standard(const input_type &v){return mint(v<0?v%mod+mod:v%mod);}
type &data(){return v;}
const type &data()const{return v;}
explicit operator type ()const{return v;}
void swap(mint &other){std::swap(v,other.v);}
friend std::istream &operator >> (std::istream &in,mint &a){return in>>a.v;}
friend std::ostream &operator << (std::ostream &out,const mint &a){return out<<a.v;}
explicit operator bool ()const{return v;}
bool operator ! ()const{return !v;}
friend bool operator == (const mint &a,const mint &b){return a.v==b.v;}
friend bool operator != (const mint &a,const mint &b){return a.v!=b.v;}
mint &operator += (const mint &b){v=v>=mod-b.v?v-(mod-b.v):v+b.v;return *this;}
mint &operator -= (const mint &b){v=v<b.v?v+(mod-b.v):v-b.v;return *this;}
mint &operator *= (const mint &b){v=type2(v)*b.v%mod;return *this;}
mint operator + ()const{return *this;}
mint operator - ()const{return mint(0)-=*this;}
mint &operator ++ (){v+1<mod?++v:v=0;return *this;}
mint operator ++ (int){mint res=*this;v+1<mod?++v:v=0;return res;}
mint &operator -- (){v?--v:v=mod-1;return *this;}
mint operator -- (int){mint res=*this;v?--v:v=mod-1;return res;}
friend mint operator + (const mint &a,const mint &b){return mint(a)+=b;}
friend mint operator - (const mint &a,const mint &b){return mint(a)-=b;}
friend mint operator * (const mint &a,const mint &b){return mint(a)*=b;}
mint inv()const{
mint x=1,y=0;
type a=v,b=mod;
for (;b;){
type t=a/b;
std::swap(a-=t*b,b);
std::swap(x-=t*y,y);
}
return x;
}
mint &operator /= (const mint &b){*this*=b.inv();return *this;}
friend mint operator / (const mint &a,const mint &b){return mint(a)/=b;}
template<class index_type>
mint pow(index_type k)const{
mint a=*this,res=1;
for (;k;k/=2,a*=a)
if (k&1) res*=a;
return res;
}
};
template<class type,class type2,std::ptrdiff_t id>
type dynamic_modint<type,type2,id>::mod=0;
}
namespace std{
template<class type,class type2,ptrdiff_t id>
void swap(hezlik::dynamic_modint<type,type2,id> &a,
hezlik::dynamic_modint<type,type2,id> &b){a.swap(b);}
}剪贴板
剪贴板 mqazx3lr
剪贴板信息
剪贴板信息
- 收录
- 更新