Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. long long X = 1, Y = 0;
  7. void euklides(unsigned long long a, unsigned long long b)
  8. {
  9. if (b != 0)
  10. {
  11. euklides(b, a%b);
  12. unsigned long long pom = Y;
  13. Y = X - (a / b * Y);
  14. X = pom;
  15. }
  16. }
  17.  
  18. unsigned long long NWD(unsigned long long x, unsigned long long y)
  19. {
  20. while (x != 0)
  21. {
  22. int ile = y / x;
  23. unsigned long long t = x;
  24. x = y - (ile*x);
  25. y = t;
  26. }
  27. return y;
  28. }
  29.  
  30. int main()
  31. {
  32. unsigned long long x, y;
  33. while (cin >> x >> y)
  34. {
  35. X = 1, Y = 0;
  36. euklides(x, y);
  37. cout << X << " " << Y << " " << NWD(x,y) << endl;
  38. }
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement