Cod sursa(job #2923124)

Utilizator CosmincreatoMarasoiu Cosmin Cosmincreato Data 11 septembrie 2022 17:55:25
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>

using namespace std;

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

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

int main()
{
    int a, b, c, d, x, y, n;
    fin >> n;
    while(n--)
    {
        fin >> a >> b >> c;
        cmmdc(a, b, d, x, y);
        if(c % d != 0) fout << "0 0 \n";
        else fout << x * (c / d) << ' ' << y * (c / d) << '\n';
    }
    return 0;
}