跳到正文

剪贴板

剪贴板 6wwixwot

原文
剪贴板信息

剪贴板信息

收录
更新
C++
template <const int mod>
struct mod32 {
	static_assert((static_cast<long long>(mod)<<1)<=INT_MAX);
	
	int val;
	explicit operator int() const {return val;}
	static constexpr int norm(int x) {return x<0?x+mod:x;}
	static constexpr int get_mod() {return mod;}
	mod32():val(0){}
	mod32(int m):val(norm(m)){}
	mod32(long long m):val(norm(m%mod)){}
	mod32<mod> operator- () const {return -val;}
	bool operator== (const mod32<mod>& x) const {return val==x.val;}
	bool operator!= (const mod32<mod>& x) const {return val!=x.val;}
	bool operator< (const mod32<mod>& x) const {return val<x.val;}
	bool operator<= (const mod32<mod>& x) const {return val<=x.val;}
	bool operator> (const mod32<mod>& x) const {return val>x.val;}
	bool operator>= (const mod32<mod>& x) const {return val>=x.val;}
	mod32<mod>& operator+= (const mod32<mod>& x) 
	{return val=(val+x.val>=mod?val+x.val-mod:val+x.val),*this;}
	mod32<mod>& operator-= (const mod32<mod>& x) 
	{return val=(val-x.val<0?val-x.val+mod:val-x.val),*this;}
	mod32<mod>& operator*= (const mod32<mod>& x)
	{return val=(static_cast<long long>(val)*x.val%mod),*this;}
	mod32<mod> pow(long long b) const 
	{mod32<mod> a(*this),res(1);for(;b;a*=a,b>>=1)if(b&1)res*=a;return res;}
//	static void exgcd(long long a,long long b,long long& x,long long& y) 
//  {return b==0?(x=1,y=0):(exgcd(b,a%b,y,x),y-=a/b*x),void();}
//	mod32<mod> operator~ () const {long long a,b;return exgcd(val,mod,a,b),a;}
	mod32<mod> operator~ () const {return pow(mod-2);}
	mod32<mod>& operator/= (const mod32<mod>& x) {return *this*=~x;}
	mod32<mod> operator+ (const mod32<mod>& x) const 
	{return mod32<mod>(*this)+=x;}
	mod32<mod> operator- (const mod32<mod>& x) const 
	{return mod32<mod>(*this)-=x;}
	mod32<mod> operator* (const mod32<mod>& x) const 
	{return mod32<mod>(*this)*=x;}
	mod32<mod> operator/ (const mod32<mod>& x) const 
	{return mod32<mod>(*this)/=x;}
	friend std::istream& operator>> (std::istream& in, mod32<mod>& x) 
	{long long v;return in>>v,x.val=norm(v%mod),in;}
	friend std::ostream& operator<< (std::ostream& out, const mod32<mod>& x)
	{return out<<x.val;}
};
using mod998244353 = mod32<998244353>;
using mod1000000007 = mod32<1000000007>;