【模板】取模类

可能有锅,谨慎使用!

由于除法用了费马小定理,所以模数必须是质数。

class mint {
	static const int mod=998244353;
public:
	int num;
	mint()=default;
	mint(long long _num) : num((_num%mod+mod)%mod) {}
	mint &operator=(long long b) {return *this=mint(b);}
	friend bool operator<(mint a,mint b) {return a.num<b.num;}
	friend bool operator>(mint a,mint b) {return a.num>b.num;}
	friend bool operator<=(mint a,mint b) {return a.num<=b.num;}
	friend bool operator>=(mint a,mint b) {return a.num>=b.num;}
	friend bool operator==(mint a,mint b) {return a.num==b.num;}
	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;}
};
posted @ 2022-12-08 20:18  Mine_King  阅读(107)  评论(1编辑  收藏  举报