Advertisement
CloneTrooper1019

UVa 10104 - Euclid Problem

Nov 26th, 2016
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #ifdef _MSC_VER
  2. #define _CRT_SECURE_NO_WARNINGS 1
  3. #endif
  4.  
  5. #include <iostream>
  6. #include <sstream>
  7.  
  8. using namespace std;
  9.  
  10. int extendEuclid(int a, int b, int &x0, int &y0)
  11. {
  12.     if (a == 0)
  13.     {
  14.         x0 = 0;
  15.         y0 = 1;
  16.         return b;
  17.     }
  18.     else
  19.     {
  20.         int x1, y1;
  21.         int d = extendEuclid(b%a, a, x1, y1);
  22.         x0 = y1 - (b / a) * x1;
  23.         y0 = x1;
  24.         return d;
  25.     }
  26. }
  27.  
  28. int main()
  29. {
  30.     int a, b, x, y;
  31.     while (scanf("%d %d", &a, &b) != EOF)
  32.     {
  33.         int d = extendEuclid(a, b, x, y);
  34.         if (a == b)
  35.         {
  36.             x = 0;
  37.             y = 1;
  38.         }
  39.         printf("%d %d %d\n", x, y, d);
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement