#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;
int a,b,c;

int exgcd(int a,int b,int &x,int &y){
    if (b==0){
        x = 1;
        y = 0;
        return a;
    }
    int d = exgcd(b,a%b,x,y);
    int temp = x;
    x = y;
    y = temp - a / b * y;
    return d;
}

int f(int a){
    if (a < 0)
        a = -a;
    return a;
}

int main(){
    //freopen("1.txt","r",stdin);
    while(scanf("%d%d%d",&a,&b,&c)!=EOF){
        if (!a && !b && !c)
            break;
        int x,y;
        int flag = 0;
        if (a < b){
            swap(a,b);
            flag = 1;
        }
        int d = exgcd(a,b,x,y);
        x = x * (c / d);
        y = y * (c / d);
        int u,v;
        u = x;
        v = y;
        int mx = 99999999;
        int x1,y1;
        int t = y * d / a; // 凹函数,极点处取最值
        for (int i = t - 5 ;i <= t + 5;i++){
            u = x + b / d * i;
            v = y - a / d * i;
            if (f(u)+f(v)<mx){
                    mx = f(u) + f(v);
                    x1 = u;
                    y1 = v;
            }
        }
        if (flag){
            printf("%d %d\n",f(y1),f(x1));
        }else {
            printf("%d %d\n",f(x1),f(y1));
        }
    }
    return 0;
}

 

posted on 2015-08-04 17:03  KingJourney  阅读(148)  评论(0)    收藏  举报