Cod sursa(job #3285667)

Utilizator AdrianRosuRosu Adrian Andrei AdrianRosu Data 13 martie 2025 12:23:21
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 kb
#include <bits/stdc++.h>
#define DIM 100001
#define int long long

using namespace std;

ifstream fin("euclid3.in");

ofstream fout("euclid3.out");

int Q, a, b, c, d, x, y;

void Modular_Inverse(int a, int b, int &d, int &x, int &y){

    if(!b){

        d = a;

        x = 1;

        y = 0;

    }

    else {

        int x1, y1;

        Modular_Inverse(b, a % b, d, x1, y1);

        x = y1;

        y = x1 - a / b * y1;

    }

}

int32_t main(){

    fin >> Q;

    while(Q--){

        fin >> a >> b >> c;

        x = y = 0;

        Modular_Inverse(a, b, d, x, y);

        if(c % d != 0)

            fout << "0 0\n";

        else {

            fout << (x * c) / d << " " << (y * c) / d << "\n";

        }

    }

}