Cod sursa(job #2664180)
| Utilizator | Data | 28 octombrie 2020 08:13:57 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <fstream>
using namespace std;
void euclid(int a, int b, int *d, int *x, int *y) {
if (b == 0) {
*d = a;
*x = 1;
*y = 0;
} else {
int x0, y0;
euclid(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
ifstream fin( "euclid3.in" );
ofstream fout( "euclid3.out" );
int main() {
int t, a, b, c, d, x, y;
fin >> t;
while( t-- ) {
fin >> a >> b >> c;
euclid( a, b, &d, &x, &y );
fout << (c % d == 0) * (c / d) * x << ' ' << (c % d == 0) * (c / d) * y << '\n';
}
return 0;
}
