Created
February 16, 2015 19:07
-
-
Save shohan4556/c224bc9bb17b9083129e to your computer and use it in GitHub Desktop.
extends euclid algo bimplement c++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <algorithm> | |
| using namespace std; | |
| int gcd(int a, int b, int &x, int &y) { | |
| if (a == 0) { | |
| x = 0; y = 1; | |
| return b; | |
| } | |
| int x1, y1; | |
| int d = gcd(b%a, a, x1, y1); | |
| x = y1 - (b/a) * x1; | |
| y = x1; | |
| return d; | |
| } | |
| int main(void) { | |
| int a, b, x, y, d; | |
| while (cin >> a >> b) { | |
| d = gcd(a, b, x, y); | |
| if (a == b) { | |
| x = 0; | |
| y = 1; | |
| } | |
| cout << x << " " << y << " " << d << endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment