Cod sursa(job #2228392)

Utilizator andreisontea01Andrei Sontea andreisontea01 Data 3 august 2018 15:45:38
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int main()
{
    ifstream fin("euclid3.in");
    ofstream fout("euclid3.out");
    int t;
    fin >> t;
    int a, b, c;
    for(int i = 1; i <= t; ++i){
        fin >> a >> b >> c;
        int x = 0, y = 0, d = 0;
        euclidExtins(a, b, d, x, y);
        if(c % d == 0)
            fout << x * (c / d) << " " << y * (c / d) << "\n";
        else
            fout << "0 0\n";
    }
    return 0;
}