首页 > 其他分享 >【模板】取模类

【模板】取模类

时间:2022-12-08 20:37:46浏览次数:41  
标签:return long 取模类 friend operator mint 模板 mod

可能有锅,谨慎使用!

class mint {
	static const int mod=998244353;
public:
	int num;
	mint()=default;
	mint(long long _num) : num(_num%mod) {}
	mint &operator=(long long b) {return *this=mint(b);}
	friend mint operator+(mint a,mint b) {return mint((a.num+b.num)%mod);}
	friend mint &operator+=(mint &a,mint b) {return a=a+b;}
	friend mint operator+(mint a,long long b) {return a+mint(b);}
	friend mint &operator+=(mint &a,long long b) {return a=a+b;}
	friend mint &operator++(mint &a) {return a+=1;}
	friend mint operator++(mint &a,int) {mint copy(a);a+=1;return copy;}
	friend mint operator-(mint a,mint b) {return mint(((a.num-b.num)%mod+mod)%mod);}
	friend mint &operator-=(mint &a,mint b) {return a=a-b;}
	friend mint operator-(mint a,long long b) {return a-mint(b);}
	friend mint &operator-=(mint &a,long long b) {return a=a-b;}
	friend mint &operator--(mint &a) {return a-=1;}
	friend mint operator--(mint &a,int) {mint copy(a);a-=1;return copy;}
	friend mint operator*(mint a,mint b) {return mint((long long)a.num*b.num%mod);}
	friend mint &operator*=(mint &a,mint b) {return a=a*b;}
	friend mint operator*(mint a,long long b) {return a*mint(b);}
	friend mint &operator*=(mint &a,long long b) {return a=a*b;}
	mint inv() {long long ans=1,a=num,b=mod-2;while (b) {if (b&1) ans=(long long)ans*a%mod;a=(long long)a*a%mod;b>>=1;}return mint(ans);}
	friend mint operator/(mint a,mint b) {return a*b.inv();}
	friend mint &operator/=(mint &a,mint b) {return a=a/b;}
	friend mint operator/(mint a,long long b) {return a/mint(b);}
	friend mint &operator/=(mint &a,long long b) {return a=a/b;}
};

标签:return,long,取模类,friend,operator,mint,模板,mod
From: https://www.cnblogs.com/mk-oi/p/mint.html

相关文章