Pagini recente » Cod sursa (job #934727) | Cod sursa (job #2456313) | Cod sursa (job #1210230) | Cod sursa (job #781349) | Cod sursa (job #2550253)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin;
ofstream fout;
int cmmdc(int x, int y)
{
/**
* Calculeaza cmmdc a doua numere
* @param x = primul numar
* @param y = al doilea numar
* @return cmmdc
*/
if (y > x)
{
int aux = x;
x = y;
y = aux;
}
while (y)
{
int r = x%y;
x = y;
y = r;
}
return x;
}
int euclid(int a, int b, int &x, int &y)
{
if (b == 0) {
x = 1;
y = 0;
return a;
} else {
int x0, y0;
int d = euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
}
int main() {
fin.open("euclid3.in");
fout.open("euclid3.out");
int x, y;
int a, b, c;
int n;
fin >> n;
for (int i=1; i<=n; i++) {
fin >> a >> b >> c;
int d = euclid(a, b, x, y);
if (c % d) {
fout << "0 0 \n";
} else {
fout << x * (c / d) << " " << y * (c / d) << '\n';
}
}
fin.close();
fout.close();
return 0;
}