Cod sursa(job #2860609)
Utilizator | Data | 2 martie 2022 20:29:01 | |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.72 kb |
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int t;
void euclid(int a, int b, int &d, int &x, int &y){
if(b == 0){
d = a;
x = 1;
y = 1;
}
else{
int x0, y0;
euclid(b, a%b, d, x0, y0);
x = y0;
y = x0-(a/b)*y0;
}
}
int main()
{
fin >> t;
for(int i=1; i<=t; i++){
int a, b, c, d, x, y;
fin >> a >> b >> c;
euclid(a, b, d, x, y);
if(c % d != 0){
x = 0;
y = 0;
}
else{
x *= (c/d);
y *= (c/d);
}
fout << x << ' ' << y << '\n';
}
return 0;
}