Advertisement
MiinaMagdy

10104 - Euclid Problem

Aug 10th, 2023
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. /*
  2. +---------------------------------------------+
  3. |                                             |
  4. |       © 10/08/2023 (00:58) MinaMagdy        |
  5. |                                             |
  6. +---------------------------------------------+
  7. */
  8. #include <bits/stdc++.h>
  9. #include <ext/pb_ds/assoc_container.hpp>
  10. #include <ext/pb_ds/tree_policy.hpp>
  11.  
  12. using namespace std;
  13. using namespace __gnu_pbds;
  14. #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
  15. #define multi_ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
  16. #define endl "\n"
  17. #define MOD 1000000007
  18. #define INF 2000000000
  19. #define all(s) s.begin(), s.end()
  20. #define rall(s) s.rbegin(), s.rend()
  21. #define sz(x) int(x.size())
  22.  
  23. typedef long long ll;
  24. typedef long double ld;
  25. typedef unsigned long long ull;
  26.  
  27. int gcd(int a, int b, int &x, int &y) {
  28.     if (b == 0) {
  29.         x = 1, y = 0;
  30.         return a;
  31.     }
  32.     int x1, y1;
  33.     int g = gcd(b, a % b, x1, y1);
  34.     x = y1;
  35.     y = x1 - a / b * y1;
  36.     return g;
  37. }
  38.  
  39. void solve() {
  40.     int a, b;
  41.     while (cin >> a >> b) {
  42.         int x, y;
  43.         int d = gcd(a, b, x, y);
  44.         cout << x << " " << y << " " << d << endl;
  45.     }
  46. }
  47.  
  48. int main(void)
  49. {
  50.     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  51.     int testcase = 1;
  52.     // cin >> testcase;
  53.     while (testcase--)
  54.         solve();
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement