Cod sursa(job #548698)

Utilizator Alexandru13Dumitraiche Marius-Alexandru Alexandru13 Data 7 martie 2011 18:30:39
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream.h>
using namespace std;
int T;
 
void EuclidExtins( int a, int b, int &d, int &x, int &y ) {
 
    int x0, y0;
 
    if( b == 0 ) {
 
        d = a;
        x = 1;
        y = 0;
    }
    else {
 
        EuclidExtins( b, a % b, d, x0, y0 );
        x = y0;
        y = x0 - (a / b) * y0;
    }
}
 
int main() {
 
    ifstream f( "euclid3.in" );
    ofstream g( "euclid3.out" );
 
    int a, b, c, d, x, y;
 
    f >> T;
    while( T!=0 ) {T--;
 
        f >> a >> b >> c;
        EuclidExtins( a, b, d, x, y );
 
        if( c % d )
            g << "0 0\n";
        else
            g << x * (c / d) << " " << y * (c / d) << "\n";
    }
 
    f.close();
    g.close(); 
    return 0;
}