Cod sursa(job #2722162)

Utilizator marius004scarlat marius marius004 Data 12 martie 2021 17:02:37
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int a, b, c;

int cmmdc(int a, int b, int& x, int& y) {

    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }

    int xa, ya;
    int d = cmmdc(b, a % b, xa, ya);

    x = ya;
    y = xa - (a / b) * ya;

    return d;
}

int main() {

    int q;
    for(f >> q;q--;) {
        f >> a >> b >> c;

        int x, y;

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

        if(c % d != 0)
            g << 0 << ' ' << 0 << '\n';
        else
            g << x * (c / d) << ' ' << y * (c / d) << '\n';
    }

    return 0;
}