嗯...
题目链接:http://poj.org/problem?id=2142
AC代码:
1 #include2 #include 3 4 using namespace std; 5 6 inline int _abs(int x){ 7 if(x < 0) return -x; 8 return x; 9 }10 11 inline void exgcd(int a, int b, int &g, int &x, int &y){12 if(!b) { g = a; x = 1; y = 0;}13 else { exgcd(b, a % b, g, y, x); y -= x * (a / b);}14 }15 16 inline void work(int a, int b, int c, int &g, int &x, int &y){17 exgcd(a, b, g, x, y);18 x *= c / g;19 int t = b / g;20 x = (x % t + t) % t;21 y = _abs((a * x - c) / b);22 }23 24 int main(){25 int a, b, c, x1, g, y1, x2, y2;26 while(~scanf("%d%d%d", &a, &b, &c)){27 if(!a && !b && !c) break;28 work(a, b, c, g, x1, y1);29 work(b, a, c, g, x2, y2);30 if(x1 + y1 < x2 + y2) printf("%d %d\n", x1, y1);31 else printf("%d %d\n", y2, x2);32 }33 return 0;34 }