Cod sursa(job #2576333)
| Utilizator | Data | 6 martie 2020 18:36:53 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void euclid(int a, int b, int &x, int &y) {
int x0, y0;
if (b == 0) {
x = 1;
y = 0;
return;
}
euclid(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
int main() {
int t, x, y, a, b, d;
fin >> t;
while (t --) {
fin >> a >> b >> d;
euclid(a, b, x, y);
if (d % __gcd(a, b) == 0) {
fout << x * (d / __gcd(a, b)) << " " << y * (d / __gcd(a, b)) << "\n";
} else {
fout << "0 0\n";
}
}
return 0;
}
