Cod sursa(job #1535886)
| Utilizator | Data | 25 noiembrie 2015 12:46:45 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 50 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.66 kb |
#include<fstream>
using namespace std;
int t, a, b, c, i, d, x, y;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int cmmdc(int a, int b, int &x, int &y){
if(b == 0){
x = 1;
y = 0;
return a;
}
else{
int da, x1, y1;
da = cmmdc(b, a % b, x1, y1);
x = y1;
y = x1 - a / b * y1;
return da;
}
}
int main(){
fin>> t;
for(; t; t--){
fin>> a >> b >> c;
d = cmmdc(a, b, x, y);
if(c % d != 0){
fout<<"0 0\n";
}
else{
fout<< x * c / d <<" "<< y * c / d <<"\n";
}
}
return 0;
}
