Pagini recente » Cod sursa (job #1266567) | Cod sursa (job #2470398) | Cod sursa (job #91956) | Cod sursa (job #764876) | Cod sursa (job #2790579)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int T, a, b, c, A[100], B[100], C, x0, y0, x, y;
int main()
{
int n;
fin >> T;
for(int i = 0; i < T; i++)
{
fin >> a >> b >> c;
n = 0;
A[0] = a, B[0] = b;
while(B[n])
{
n++;
A[n] = B[n-1];
B[n] = A[n-1] % B[n-1];
}
if(c % A[n])
fout<<"0" << " " << "0";
else
{
x0 = c / A[n];
y0 = 0;
while(n)
{
n--;
x = y0;
y = x0 - A[n] / B[n] * y0;
x0 = x;
y0 = y;
}
if(x0 == 0)
fout << "0" << " " << "0" << "\n";
else
fout << x0 << " " << y0 << "\n";
}
}
return 0;
}