Cod sursa(job #2561731)

Utilizator vmnechitaNechita Vlad-Mihai vmnechita Data 29 februarie 2020 09:39:14
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <fstream>

using namespace std;

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

int x, y;
int Euclid_extins ( int a, int b );

int main()
{
    int t, a, b, c, d;

    fin >> t;
    while ( t-- )
    {
        fin >> a >> b >> c;

        d = Euclid_extins ( a, b );

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

    return 0;
}

int Euclid_extins ( int a, int b )
{
    int cx, d;

    if ( b == 0 )
    {
        x = 1;
        y = 0;
        return a;
    }

    else
    {
        d = Euclid_extins ( b, a % b );
        cx = x;
        x = y;
        y = cx - ( a / b ) * y;

        return d;
    }
}