감 ¶
2005/03/31 Accepted 0:01.820 436
론 본 리드 고리 문다. AX + BY = GCD gcd x, y 구는 법 문보 래 가고 기 때문 단 copy&paste로 문를 다.
론 본 리드 고리 문다. AX + BY = GCD gcd x, y 구는 법 문보 래 가고 기 때문 단 copy&paste로 문를 다.
드 ¶
~cpp // no10104 - Euclid Problem #include <iostream> #include <cmath> using namespace std; int gcd(int p, int q, int & x, int & y); int main() { int a, b; int x, y; int g; // gcd while (cin >> a >> b) { g = gcd(a, b, x, y); cout << x << " " << y << " " << g << endl; } return 0; } int gcd(int p, int q, int & x, int & y) { int x1, y1; // int g; // gcd if (p < q) return (gcd(q, p, y, x)); if (q == 0) { x = 1; y = 0; return p; } g = gcd(q, p%q, x1, y1); x = y1; y = (x1 - floor(p/q) * y1); return g; }