Cod sursa(job #2884195)
Utilizator | Cristian Alexutan DooMeD | Data | 2 aprilie 2022 15:59:36 |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void euclid(ll a, ll b, ll &d, ll &x, ll &y) {
if(b==0) {
d = a;
x = 1;
y = 0;
}
else {
ll x1, y1;
euclid(b, a%b, d, x1, y1);
x = y1;
y = x1 - 1LL * (a / b) * y1;
}
}
int main() {
ifstream f("euclid3.in");
ofstream g("euclid3.out");
ll t; f >> t;
while(t--) {
ll a, b, c; f >> a >> b >> c;
ll d, x, y;
euclid(a, b, d, x, y);
if(c % d == 0)
g << (c/d) * x << " " << (c/d) * y << "\n";
else g << "0 0\n";
}
return 0;
}