2142

/*
扩展欧几里得

a x1 x2
b y1 y2

(a*x1+b*y1) - (a*x2+b*y2) = d
a*x+b*y = D
*/

// include file
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>

#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <functional>

using namespace std;

// typedef
typedef __int64 LL;

// 
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)

#define Z(a,b) ((a)<<(b))
#define Y(a,b) ((a)>>(b))

const double eps = 1e-6;
const double INFf = 1e100;
const int INFi = 1000000000;
const LL INFll = (LL)1<<62;
const double Pi = acos(-1.0);

template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T TMAX(T x,T y)
{
	if(x>y) return x;
	return y;
}
template<class T> inline T TMIN(T x,T y)
{
	if(x<y) return x;
	return y;
}
template<class T> inline T MMAX(T x,T y,T z)
{
	return TMAX(TMAX(x,y),z);
}
template<class T> inline T MMIN(T x,T y,T z)
{
	return TMIN(TMIN(x,y),z);
}
template<class T> inline void SWAP(T &x,T &y)
{
	T t = x;
	x = y;
	y = t;
}


// code begin
int A,B,D,a,b,d,gd,x,y,ansx,ansy,ans;
int gcd(int aa,int bb)
{
	if(bb==0) return aa;
	return gcd(bb,aa%bb);
}
int extGcd(int aa,int bb,int &x,int &y)
{
	if(bb==0)
	{
		x = 1;
		y = 0;
		return aa;
	}
	int r = extGcd(bb,aa%bb,x,y);
	int t = x;
	x = y;
	y = t-aa/bb*x;
	return r;
}
int main()
{
	read;
	write;
	while(scanf("%d %d %d",&A,&B,&D)==3)
	{
		if(A+B+D==0) break;
		a = A;
		b = B;
		d = gcd(a,b);
		a/=d;
		b/=d;
		D/=d;
		extGcd(a,b,x,y);
		x*=D;
		y*=D;
		// x0+bt 0
		// y0-at 10000
		//printf("%d %d %d %d\n",a,b,x,y);
		ansx = INFi;
		ansy = INFi;
		ans = INFi;
		int l = -x/b;
		int r = y/a;
		if(l>r) SWAP(l,r);
		//printf("%d %d\n",l,r);
		for(int t=l-1;t<=r+1;t++)
		{
			
			int xx = x+b*t;
			int yy = y-a*t;

			if( abs(xx)+abs(yy)<ansx+ansy || ( abs(xx)+abs(yy)==ansx+ansy && (ans==INFi || abs(xx)*A+abs(yy)*B<ans) ) )
			{
				ansx = abs(xx);
				ansy = abs(yy);
				ans = abs(xx)*A+abs(yy)*B;
			}
		
	
		}
		
		printf("%d %d\n",ansx,ansy);
	}
	return 0;
}

posted @ 2011-04-30 17:21  AC2012  阅读(180)  评论(0编辑  收藏  举报