Pagini recente » Cod sursa (job #1123686) | Cod sursa (job #2061951) | concurs-mihai-patrascu-2013/clasament | Monitorul de evaluare | Cod sursa (job #2580523)
#include <bits/stdc++.h>
using namespace std;
int solve(int a, int b, int &x, int &y)
{
if(!b)
{
x = 1;
y = 0;
return a;
}
int x0, y0;
int d = solve(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main()
{
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
ios::sync_with_stdio(false);
fin.tie(0);
fout.tie(0);
int n;
fin >> n;
for(int i = 1; i <= n; i++)
{
int a, b, z;
fin >> a >> b >> z;
int x, y;
int d = solve(a, b, x, y);
if(z % d)
fout << "0 0" << '\n';
else
{
int bias = z / d;
fout << x * bias << " " << y * bias << '\n';
}
}
fin.close();
fout.close();
return 0;
}