Pagini recente » Cod sursa (job #764294) | Monitorul de evaluare | Cod sursa (job #1306661) | Cod sursa (job #2291348) | Cod sursa (job #2221299)
#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
using namespace std;
long long int cmmdc(long long int a, long long int b)
{
if(a == 0)
return b;
if(b == 0)
return a;
if(a < b)
return cmmdc(b, a);
return cmmdc(a % b, b);
}
void solve()
{
long long int a, b, c;
scanf("%lld", &a);
scanf("%lld", &b);
scanf("%lld", &c);
long long int ax = abs(a);
long long int by = abs(b);
long long int d = cmmdc(ax, by);
if(c % d != 0)
{
printf("0 0\n");
return;
}
while(abs(ax - by) != d)
{
if(ax > by)
{
by += ((ax - by) / b + 1) * b;
}
else
{
ax += ((by - ax) / a + 1) * a;
}
}
if(a < 0)
ax = -ax;
if(b < 0)
by = -by;
if(ax - by == -d)
{
ax = -ax;
by = -by;
}
long long int x = ax / a;
long long int y = -by / b;
long long int deCateOriIntra = c / d;
x *= deCateOriIntra;
y *= deCateOriIntra;
printf("%lld %lld\n", x, y);
}
int main()
{
freopen("euclid3.in", "r", stdin);
freopen("euclid3.out", "w", stdout);
int t;
scanf("%d", &t);
for(int test = 0; test < t; ++test)
{
solve();
}
return 0;
}