Matrix_code

chore - Useful small function

Mar 23rd, 2020 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. inline long long bigmod(long long p,long long e,long long M){
  2.     long long ret = 1;
  3.     for(; e > 0; e >>= 1){
  4.         if(e & 1) ret = (ret * p) % M;
  5.         p = (p * p) % M;
  6.     } return ret;
  7. }
  8. template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
  9. template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
Add Comment
Please, Sign In to add comment