Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef _MSC_VER
- #define _CRT_SECURE_NO_WARNINGS 1
- #endif
- #include <iostream>
- #include <sstream>
- using namespace std;
- int extendEuclid(int a, int b, int &x0, int &y0)
- {
- if (a == 0)
- {
- x0 = 0;
- y0 = 1;
- return b;
- }
- else
- {
- int x1, y1;
- int d = extendEuclid(b%a, a, x1, y1);
- x0 = y1 - (b / a) * x1;
- y0 = x1;
- return d;
- }
- }
- int main()
- {
- int a, b, x, y;
- while (scanf("%d %d", &a, &b) != EOF)
- {
- int d = extendEuclid(a, b, x, y);
- if (a == b)
- {
- x = 0;
- y = 1;
- }
- printf("%d %d %d\n", x, y, d);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement