-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmod.cpp
More file actions
24 lines (24 loc) · 1010 Bytes
/
mod.cpp
File metadata and controls
24 lines (24 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
constexpr int MOD = 1000000007;
struct MOD_INT{
int x;
MOD_INT(const int& x=0) : x((x%MOD+MOD)%MOD){}
MOD_INT(const ll& x) : x((x%MOD+MOD)%MOD){}
MOD_INT(const MOD_INT& o): x(o.x){}
operator int(){return x;}
MOD_INT pow(int e) {
MOD_INT res(1), b(*this);
for (; e >>1; b=b*b) if (e&1) res = res*b;
return res;
}
MOD_INT inv() {return pow(MOD-2);}
template<class T> MOD_INT operator+(T o){return MOD_INT(x+MOD_INT(o).x);}
template<class T> MOD_INT operator-(T o){return MOD_INT(x-MOD_INT(o).x);}
template<class T> MOD_INT operator*(T o){return MOD_INT((ll)x*MOD_INT(o).x);}
template<class T> MOD_INT operator/(T o){return *this*MOD_INT(o).inv();}
};
#define DEFOP(OP, OPEQ) \
template<class T> MOD_INT& operator OPEQ(MOD_INT& a, T o){return a=a OP o;}\
template<class T> MOD_INT operator OP(T a, MOD_INT b){return MOD_INT(a).operator OP(b);}
DEFOP(+, +=); DEFOP(-, -=); DEFOP(*, *=); DEFOP(/, /=);
#undef DEFOP
typedef MOD_INT mi;