Created
December 12, 2012 10:39
-
-
Save MiSawa/4266793 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
typedef long long ll; | |
using namespace std; | |
const int MOD = (int)(1E9+7); | |
struct MOD_INT{//{{{ | |
int x; | |
MOD_INT(const int &x=0): x((x%MOD+MOD)%MOD){} | |
MOD_INT(const ll &x=0): 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; 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) OP b.x;} | |
DEFOP(+, +=); DEFOP(-, -=); DEFOP(*, *=); DEFOP(/, /=); | |
#undef DEFOP | |
//}}} | |
typedef MOD_INT mi; | |
int main(void){ | |
mi a = 10, b = 20; | |
cout << a*b/a << endl; | |
b = a += b; | |
cout << a << endl; | |
cout << b << endl; | |
} | |
/* vim:set foldmethod=marker commentstring=//%s : */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment