Advertisement
double_trouble

GCD extended

Feb 26th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <cmath>
  6. #include <string>
  7. #include <algorithm>
  8. #include <string>
  9. #include <deque>
  10. #include <iomanip>
  11. #include <cstddef>
  12.  
  13. #define F first
  14. #define S second
  15.  
  16. using namespace std;
  17.  
  18.  
  19. const long double eps = 0.000000005;
  20. const long double pi = 3.1415926535897932;
  21. const long long inf = 1e9;
  22.  
  23. vector<vector<int, int> > g;
  24. vector<bool> used;
  25. vector <int> d;
  26.  
  27. int gcd_ext(int& x, int& y, int a, int b)
  28. {
  29.     if (b == 0)
  30.     {
  31.         x = 1;
  32.         y = 0;
  33.         return a;
  34.     }
  35.     int x1, y1;
  36.     int g = gcd_ext(x1, y1, b, a%b);
  37.     x = y1;
  38.     y = x1 - y1 * a / b;
  39. }
  40.  
  41. int main()
  42. {
  43.     ios_base::sync_with_stdio(0);
  44.     //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
  45.     // freopen("slalom.in", "r", stdin);freopen("slalom.out", "w", stdout);
  46.  
  47.     int a, b, c;
  48.     cin >> a >> b >> c;
  49.  
  50.     int x, y;
  51.  
  52.     int ans = gcd_ext(x, y, a, b);
  53.  
  54.  
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement