Pagini recente » Cod sursa (job #2115610) | Cod sursa (job #2437493) | Cod sursa (job #1631970) | Cod sursa (job #2372627) | Cod sursa (job #2254608)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("euclid3.in");
ofstream g ("euclid3.out");
int n,a,b,c,d,x,y,cmmdc(int,int,int&,int&);
int main()
{
f >> n;
for(;n;n--)
{
f >> a >> b >> c;
d = cmmdc(a,b,x,y);
if(c%d)
g << "0 0\n";
else
{
x = c/d * x;
y = c/d * y;
g << x << " " << y << "\n";
}
}
return 0;
}
int cmmdc(int a,int b,int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
int X,Y,D;
D = cmmdc(b,a%b, X,Y);
x = Y;
y = X-a/b*Y;
return D;
}