Cod sursa(job #3341570)

Utilizator cyg_vladioanBirsan Vlad cyg_vladioan Data 20 februarie 2026 00:52:34
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <fstream>

void extended_gcd(int a, int b, int* d, int* x, int* y) {
    if(!b) {
        *d = a;
        *x = 1;
        *y = 0;
    } else {
        int x0, y0;
        extended_gcd(b, a % b, d, &x0, &y0);
        *x = y0;
        *y = x0 - (a / b) * y0;
    }
}

int main() {
    std::ifstream fin("euclid3.in");
    std::ofstream fout("euclid3.out");

    int T, a, b, c, x, y, d;
    fin >> T;

    for( ; T; -- T) {
        fin >> a >> b >> c;
        extended_gcd(a, b, &d, &x, &y);
        if(c % d == 0) {
            fout << x * (c / d) << " " << y * (c / d) << "\n";
        } else {
            fout << "0 0\n";
        }
    }

    return 0;
}