Pagini recente » Cod sursa (job #46497) | Cod sursa (job #198506) | Cod sursa (job #339162) | Cod sursa (job #717797) | Cod sursa (job #1532113)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
void extendedgcd(int a, int b, int &x, int &y) {
if(b == 0) {
x = 1;
y = 0;
return ;
}
int x0, y0;
extendedgcd(b, a % b, x0, y0); /// calculam solutiile ecuatiei b * x0 + (a % b) * y0 = d
x = y0;
y = x0 - (a / b) * y0;
}
int main()
{
int n,a,b,c;
in>>n;
for(int i=1;i<=n;i++)
{
in>>a>>b>>c;
int d = gcd(a, b);
int x, y;
extendedgcd(a, b, x, y);
/// solutiile ecuatiei a * x + b * y = d solutiile ecuatiei a * x + b * y = c
/// (c / d) * (a * x + b * y) = c
/// a * (x * c / d) + b * (y * c /d) = c
if(c % d != 0)
out << "0 0\n";
else
out << x * (c / d) << ' ' << y * (c / d) << '\n';
}
return 0;
}