Cod sursa(job #3155136)

Utilizator LauraNaduLaura Nadu LauraNadu Data 7 octombrie 2023 13:49:01
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.89 kb
#include <fstream>
#include <iostream>
using namespace std;

/*

(a, b, c) => (x, y) ?

T - no tests [1, 100]
a, b -> [-1 000 000 000, 1 000 000 000]
c -> [-2 000 000 000, 2 000 000 000]

x, y -> [-2 000 000 000, 2 000 000 000]
*/

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

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

int main() {
    ifstream read("euclid3.in");
    ofstream write("euclid3.out");

    int T;
    read >> T;

    while (T > 0) {
        int a, b, c, x, y;
        read >> a >> b >> c;

        int d = cmmdc(a, b, x, y);

        if (c % d != 0) {
            write << "0 0\n";
        } else {
            write << x * (c / d) << " " << y * (c / d) << "\n";
        }

        T--;
    }

    return 0;
}