Cod sursa(job #3156933)

Utilizator stefan_dore_Stefan Dore stefan_dore_ Data 13 octombrie 2023 18:53:05
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream f ("euclid3.in");
ofstream g ("euclid3.out");

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

int main()
{
    int T, d, x, y, a, b, c;
    f >> T;
    while (T--) {
        f >> a >> b >> c;
        euclidExtins(a, b, d, x, y);
        if (c%d != 0)
            g << 0 << ' ' << 0 << '\n';
        else
            g << x*(c/d) << ' ' << y*(c/d) << '\n';
    }
    return 0;
}