Cod sursa(job #1126073)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 26 februarie 2014 21:09:57
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <iostream>
#include <fstream>

using namespace std;

void gcd( int a, int b, int &d, int &x, int &y )
{
    if ( !b )
    {
        d = a;
        x = 1;
        y = 0;
    }
    else
    {
        int x0, y0;

        gcd( b, a % b, d, x0, y0 );

        x = y0;
        y = x0 - ( a / b ) * y0;
    }
}

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

int main()
{
    ifstream f("euclid3.in");
    ofstream g("euclid3.out");

    f >> T;

    while ( T-- )
    {
        f >> a >> b >> c;

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

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

    return 0;
}