Araf_12

MOD

Mar 16th, 2021 (edited)
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | Source Code | 0 0
  1. inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
  2. inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
  3. inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
  4. inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
  5. inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
  6. inline ll modInverse(ll a) { return modPow(a, MOD-2); }
  7. inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
Add Comment
Please, Sign In to add comment