Cod sursa(job #533084)

Utilizator ssergiussSergiu-Ioan Ungur ssergiuss Data 13 februarie 2011 00:17:10
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include <algorithm>
#include <fstream>

using namespace std;

const char Input[] = "euclid3.in";
const char Output[] = "euclid3.out";

int T;

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

    int x0, y0;

    if( b == 0 ) {

        d = a;
        x = 1;
        y = 0;
    }
    else {

        EucEx( b, a % b, d, x0, y0 );
        x = y0;
        y = x0 - (a / b) * y0;
    }
}

int main() {

    ifstream fin( Input );
    ofstream fout( Output );

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

    fin >> T;
    while( T-- ) {

        fin >> a >> b >> c;
        EucEx( a, b, d, x, y );

        if( c % d )
            fout << "0 0\n";
        else
            fout << x * c / d << " " << y * c / d << "\n";
    }

    fin.close();
    fout.close();

    return 0;
}