fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7. using ll = long long;
  8. using ld = long double;
  9.  
  10. #define all(x) x.begin(),x.end()
  11. #define v(x) vector<x>
  12. #define nl '\n'
  13. #define fxd(x) fixed << setprecision(x)
  14. template<class t> using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
  15. template<class t> using ordered_multiset = tree<t, null_type, less_equal<t>, rb_tree_tag, tree_order_statistics_node_update>;
  16.  
  17.  
  18.  
  19. ll ExtendedEclideanRec(ll a , ll b , ll &x , ll &y)
  20. {
  21. if(b == 0)
  22. {
  23. x = 1;
  24. y = 0;
  25. return a;
  26. }
  27.  
  28. ll x1 , y1;
  29. ll gc = ExtendedEclideanRec(b,a%b,x1,y1);
  30.  
  31. x = y1;
  32. y = x1 - y1 * (a/b);
  33.  
  34. return gc;
  35. }
  36.  
  37. int main()
  38. {
  39. ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  40. ll a , b;
  41. while (cin >> a >> b)
  42. {
  43. ll x , y,d;
  44. d = ExtendedEclideanRec(a,b,x,y) ;
  45. cout << x << " " << y << " " << d << nl;
  46. }
  47. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty