Cod sursa(job #2722146)
Utilizator | scarlat marius marius004 | Data | 12 martie 2021 16:52:22 |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.63 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.in");
int a, b, c;
int cmmdc(int a, int b, int& x, int& y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
int xa, ya;
int d = cmmdc(b, a % b, xa, ya);
x = ya;
y = xa - (a / b) * ya;
return d;
}
int main() {
int q;
for(f >> q;q--;) {
f >> a >> b >> c;
int x, y;
int d = cmmdc(a, b, x, y);
if(c % d != 0)
g << 0 << ' ' << 0 << '\n';
else
g << x * (c / d) << ' ' << y * (c / d) << '\n';
}
return 0;
}