Advertisement
jelyslime

Broi teglilki zad

Jan 26th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int gcdExtended(int a, int b, int *x, int *y)
  7. {
  8.    
  9.     if (a == 0)
  10.     {
  11.         *x = 0;
  12.         *y = 1;
  13.         return b;
  14.     }
  15.  
  16.     int x1, y1;
  17.     int gcd = gcdExtended(b%a, a, &x1, &y1);
  18.  
  19.      
  20.     *x = y1 - (b / a) * x1;
  21.     *y = x1;
  22.  
  23.     return gcd;
  24. }
  25.  
  26. int main() {
  27.     int x, y;
  28.     int a,b;
  29.     cout << "Vuvedi dvete chisla" << endl;
  30.     cin >> a >> b;
  31.  
  32.     x = 0;
  33.     y = 0;
  34.    
  35.     int rez = gcdExtended(a, b, &x, &y);
  36.    
  37.     int broiteglilki = abs(x) + abs(y);
  38.    
  39.     cout << "Gcd = " << rez << " x = " << x << " y = " << y <<  " Broi teglilki: " << broiteglilki <<endl;
  40.  
  41.  
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement