Cod sursa(job #2710678)
| Utilizator | Data | 22 februarie 2021 20:50:47 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <fstream>
#define f in
#define g out
using namespace std;
ifstream in ( "euclid3.in" );
ofstream out( "euclid3.out" );
int m, a, b, c, d, x, y;
int cmmdc ( int a, int b, int &x, int &y ){
if ( !b ){
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() {
for ( f>>m; m--; ){
f>>a>>b>>c;
x = y = 0;
d = cmmdc ( a, b, x, y );
if ( c%d )
g<<"0 0\n";
else g<<x*(c/d)<<" "<<y*(c/d)<<"\n";
}
return 0;
}
