Cod sursa(job #3203910)

Utilizator JulyaBuhBuhai Iulia JulyaBuh Data 14 februarie 2024 23:36:38
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

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

int main() {
    int T;
    fin >> T;

    for (int t = 0; t < T; ++t) {
        int a, b, c;
        fin >> a >> b >> c;

        int x, y, d;
        euclid_extended(a, b, c, x, y, d);

        if (c % d == 0) {
            fout << x << " " << y << "\n";
        } else {
            fout << "0 0\n";
        }
    }

    return 0;
}