Cod sursa(job #3136240)

Utilizator sandu123412Alexandru Gheorghita sandu123412 Data 5 iunie 2023 18:36:03
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream intrare("euclid3.in");
ofstream iesire("euclid3.out");

int gcd_extins(long int a, long int b, long int &x, long int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }

    long int x0, y0;
    long int d = gcd_extins(b, a % b, x0, y0);
    x = y0;
    y = x0 - (a / b) * y0;
    return d;
}

int main() {
    long int n, a, b, c, x0, y0, d;
    intrare >> n;
    for (int i = 0; i < n; i++) {
        intrare >> a >> b >> c;
        d = gcd_extins(a, b, x0, y0);
        if (c % d)
            iesire << 0 << " " << 0 << '\n';
        else
            iesire << x0 * (c / d) << " " << y0 * (c / d) << '\n';
    }
    return 0;
}