Cod sursa(job #2664341)

Utilizator 2016Teo@Balan 2016 Data 28 octombrie 2020 15:27:27
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>
using namespace std;
#define f1 "euclid3.in"
#define f2 "euclid3.out"
ifstream in(f1);
ofstream out(f2);
void eclext(int a, int b, int *d, int *x, int *y) {
    if (b == 0) {
        *d = a;
        *x = 1;
        *y = 0;
    } else {
        int x0, y0;
        eclext(b, a % b, d, &x0, &y0);
        *x = y0;
        *y = x0 - (a / b) * y0;
    }
}
int main() {
    int q, a, b, c, d, x, y;
    in >> q;
    while(q--) {
        in >> a >> b >> c;
        eclext(a, b, &d, &x, &y);
        if(c % d == 0)
            out << x * (c / d) << " " << y * (c / d) << '\n';
        else
            out << "0 0 \n";
    }
    return 0;
}