Cod sursa(job #3181625)

Utilizator AnSeDraAndrei Sebastian Dragulescu AnSeDra Data 7 decembrie 2023 15:33:30
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <fstream>

using namespace std;

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

    int xp, yp;

    euclid_extins(b, a % b, d, xp, yp);
    x = yp;
    y = xp - (a / b) * yp;
}

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

    int t, a, b, c, d, x, y;
    pair<int, int> sol;

    fin >> t;

    while(t--){
        fin >> a >> b >> c;

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

        if(c % d != 0){
            sol = {0, 0};
        }
        else{
            sol = {x * (c / d), y * (c / d)};
        }

        fout << sol.first << " " << sol.second << '\n';
    }

    return 0;
}