#include #include #include #include #include #include #include #include #include using namespace std; typedef pair res; struct lessres { int x, y; lessres(int x, int y) : x(x), y(y) {} bool operator() (const res& a, const res& b) { if(a.first + a.second != b.first + b.second) return a.first + a.second < b.first + b.second; //if(a.first * x + a.second * y != b.first * x + b.second * y) return a.first * x + a.second * y < b.first * x + b.second * y; } }; int Euclid(int a, int b, int* x, int* y) { int x0 = 1, x1 = 0; int y0= 0, y1 = 1; int sign = 1; while (b) { int r = a % b, q = a / b; a = b, b = r; int tx1 = x1, ty1 = y1; x1 = q * x1 + x0, y1 = q * y1 + y0; x0 = tx1, y0= ty1; sign = -sign; } if (a >=0) { *x = sign * x0; *y = -sign * y0; return a; } else { *x = -sign * x0; *y = sign *y0; return -a; } } int gcd(int a, int b) { while (b) { int t = a % b; a = b; b = t; } return a; } ifstream fin("A.txt"); #define cin fin void improve(int a, int b, int& x, int& y) { // ax' + by' = 0 int g = gcd(a, b); a /= g; b /= g; a = abs(a); b = abs(b); while (x < 0 || y < 0) { x += b; y += a; } while (x - b >= 0 && y - a >= 0) { x -= b; y -=a; } } void solve(int a, int b, int d, int& x, int& y) { int x0, y0; int g = Euclid(a, b, &x0, &y0); assert(d % g == 0); int t = abs(d / g); x0 *= t; y0 *= t; //cout << "gcd(" << a << "," << b << ") = " << g << ", x=" << x0 << "/y=" << y0 << endl; x = x0; y = y0; improve(a, b, x, y); } void improve2(int a, int b, int& x, int& y) { // ax' + by' = 0 int g = gcd(a, b); a /= g; b /= g; //a = abs(a); //b = abs(b); //cout << x << ',' << y << endl; if(x < 0) while(x < 0) { x += b; y -= a; } else if(y < 0) while(y < 0) { x -= b; y += a; } if(a < b) { while (x >= b) { x -= b; y += a; } }else { while (y >= a) { x += b; y -=a; } } } void solve2(int a, int b, int d, int& x, int& y) { int x0, y0; int g = Euclid(a, b, &x0, &y0); assert(d % g == 0); int t = abs(d / g); x0 *= t; y0 *= t; //cout << "gcd(" << a << "," << b << ") = " << g << ", x=" << x0 << "/y=" << y0 << endl; x = x0; y = y0; improve2(a, b, x, y); } int main() { if(!fin) return -1; int a, b, d; while (cin >> a >> b >> d, (a || b || d)) { lessres comp(a, b); int x0, y0; solve(a, -b, d, x0, y0); //cout << "solve1: " << x0 << " " << y0 << endl; res result(x0, y0); solve(-a, b, d, x0, y0); //cout << "solve2: " << x0 << " " << y0 << endl; if(comp(res(x0, y0), result)) result = res(x0, y0); solve2( a, b, d, x0, y0); if(x0 >= 0 && y0 >= 0) { //cout << "solve3: " << x0 << " " << y0 << endl; if(comp(res(x0, y0), result)) result = res(x0, y0); } cout << result.first << ' ' << result.second << endl; } return 0; }