Advertisement
Emiliatan

a289

Jul 2nd, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. /* a289            */
  2. /* AC (0.1s, 88KB) */
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. typedef long long int64;
  8.  
  9. int64 x, y, a, b;
  10. int64 exgcd(int64 a, int64 b)
  11. {
  12.       if(b == 0)
  13.       {
  14.               x = 1;
  15.               y = 0;
  16.               return a;
  17.       }
  18.       int64 r = exgcd( b, a % b );
  19.       int64 tmp = x;
  20.       x = y;
  21.       y = tmp - a / b * y;
  22.       return r;
  23. }
  24.  
  25. int main()
  26. {
  27.       while(~scanf("%lld %lld", &a, &b))
  28.             if(b != 1 && exgcd(a, b) == 1)
  29.                 printf("%lld\n", (x % b + b) % b);
  30.             else
  31.                 puts("No Inverse");
  32.  
  33.       return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement