Created
March 13, 2018 11:52
-
-
Save maehrm/fc9181f516da9ef14f23c6275bed542f to your computer and use it in GitHub Desktop.
Extended Euclid Algorithm | Aizu Online Judge http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_E&lang=jp
This file contains 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> | |
using namespace std; | |
int extgcd(int a, int b, int *x, int *y) { | |
int d = a; | |
if (b != 0) { | |
d = extgcd(b, a % b, y, x); | |
*y -= (a / b) * *x; | |
} | |
else { | |
*x = 1; *y = 0; | |
} | |
return d; | |
} | |
int main(){ | |
int a, b, x, y; | |
cin >> a >> b; | |
extgcd(a, b, &x, &y); | |
cout << x << " " << y << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment