Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created March 13, 2018 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maehrm/fc9181f516da9ef14f23c6275bed542f to your computer and use it in GitHub Desktop.
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
#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