Cod sursa(job #2183369)
| Utilizator | Data | 23 martie 2018 09:16:37 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
ll a, b, c, d, x, y;
void euclid(ll a, ll b, ll &d, ll &x, ll &y){
if(b == 0){
d = a;
x = 1;
y = 0;
} else {
ll x0, y0;
euclid (b, a % b, d, x0, y0);
x = y0;
y = x0 - y0 * (a / b);
}
}
int main(){
in >> a;
while(in >> a >> b >> c){
x = 0; y = 0;
euclid(a, b, d, x, y);
if(c % d){
out << "0 0\n";
continue;
}
out << x * (c / d) << ' ' << y * (c / d) << '\n';
}
return 0;
}
