Cod sursa(job #2661137)

Utilizator SergiuS3003Sergiu Stancu Nicolae SergiuS3003 Data 21 octombrie 2020 14:16:51
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ( "euclid3.in" );
ofstream g ( "euclid3.out" );
int euclid ( int a, int b, int &x, int &y )
{
    if ( b == 0 )
    {
        x = 1;
        y = 0;
        return a;
    }

    int x0, y0, d;
    d = euclid ( b, a % b, x0, y0 );
    int c = a / b;
    x = y0;
    y = x0 - c * y0;
    return d;
}
int main()
{
    int T;
    f >> T;

    while ( T-- )
    {
        int a, b, x, y, c;
        f >> a >> b >> c;
        int d = euclid ( a, b, x, y );
        cout<<x<<' '<<y<<'\n';
        if ( c % d != 0 )
            g << 0 << ' ' << 0 << '\n';
        else g << x*c / d << ' ' << y*c / d << '\n';
    }

    return 0;
}