1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
using namespace std;
//======================================================================
bool trial( int &i, int &j, int x, int y, int n )
{
if ( !x )
{
i = 0;
j = n / y;
return !( n % y );
}
else
{
int ip, jp;
bool result = trial( ip, jp, y % x, x, n );
j = ip;
i = jp - j * ( y / x );
return result;
}
}
//======================================================================
int hcf( int a, int b ) { return b == 0 ? a : hcf( b, a % b ); }
//======================================================================
int main()
{
int x, y, n, i, j;
cin >> n >> x >> y;
int h = hcf( x, y );
if ( n % h )
{
cout << -1 << '\n';
return 0;
}
n /= h; x /= h; y /= h;
if ( !trial( i, j, x, y, n ) )
{
cout << -1 << '\n';
}
else
{
if ( j < 0 ) { j += ( i / y ) * x; i %= y; }
else if ( i < 0 ) { i += ( j / x ) * y; j %= x; }
if ( i >= 0 && j >= 0 ) cout << i << " " << j << '\n';
else cout << -1 << '\n';
}
}
|