Cod sursa(job #3041962)

Utilizator Fantastic_Mantudor voicu Fantastic_Man Data 3 aprilie 2023 10:40:21
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <fstream>

using namespace std;

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

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

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

    return 0;
}