surajmateti

extented euclid

Jun 13th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. ll d, x, y;
  2. void extendedEuclid(ll A, ll B) {
  3.     if(B == 0) {
  4.         d = A;
  5.         x = 1;
  6.         y = 0;
  7.     }
  8.     else {
  9.         extendedEuclid(B, A%B);
  10.         ll temp = x;
  11.         x = y;
  12.         y = temp - (A/B)*y;
  13.     }
  14. }
  15. ll modinv(ll a){
  16.    extendedEuclid(a,m);
  17.     return (x%m+m)%m;
  18. }
Add Comment
Please, Sign In to add comment