Cod sursa(job #1256405)

Utilizator hanganflorinHangan Florin hanganflorin Data 6 noiembrie 2014 10:59:35
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 4.52 kb
#include <fstream>
using namespace std;

ifstream is("euclid3.in");
ofstream os("euclid3.out");

void Euclid(int a, int b, int & d, int &x, int &y );
int a, b, c, d, x, y;
int t;

int main()
{
    is >> t;
    while ( t-- )
    {
        is >> a >> b >> c;
        Euclid(a, b, d, x, y );
        os << d << "  ";
        if ( c % d )
            os << "0 0\n";
        else
            os << x * (c/d) << ' ' << y * (c/d)<< '\n';
    }

    is.close();
    return 0;
}
void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
    Euclid(b, a%b, d, x0, y0 );
    x = y0;
    y = x0 - (a/b) * y0;
}


24 15 147
                24     15      0       0       0
void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
           15  9  0  0    0
    Euclid(b, a%b, d, x0, y0 ); x0 = 1 y0 = -1
    x = y0; // -1
    y = x0 - (a/b) * y0; // 2
}

                15     9      0       0       0
void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
           9   6   0   0  0
    Euclid(b, a%b, d, x0, y0 ); x0 = 0 y0 = 1;
    x = y0; // 1
    y = x0 - (a/b) * y0;  //-1
}

                9      6       0       0       0
void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
           6   3   0   0   0
    Euclid(b, a%b, d, x0, y0 ); x0 = 1 y0 = 0;
    x = y0; // 0
    y = x0 - (a/b) * y0;  // 1
}

                6      3
void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
           3   0   0  0   0
    Euclid(b, a%b, d, x0, y0 );
    x = y0;
    y = x0 - (a/b) * y0;
}

                3      0
void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
    Euclid(b, a%b, d, x0, y0 );
    x = y0;
    y = x0 - (a/b) * y0;
}


void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
    Euclid(b, a%b, d, x0, y0 );
    x = y0;
    y = x0 - (a/b) * y0;
}


void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
    Euclid(b, a%b, d, x0, y0 );
    x = y0;
    y = x0 - (a/b) * y0;
}


void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
    Euclid(b, a%b, d, x0, y0 );
    x = y0;
    y = x0 - (a/b) * y0;
}


void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
    Euclid(b, a%b, d, x0, y0 );
    x = y0;
    y = x0 - (a/b) * y0;
}


void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
    Euclid(b, a%b, d, x0, y0 );
    x = y0;
    y = x0 - (a/b) * y0;
}


void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
    Euclid(b, a%b, d, x0, y0 );
    x = y0;
    y = x0 - (a/b) * y0;
}


void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
    Euclid(b, a%b, d, x0, y0 );
    x = y0;
    y = x0 - (a/b) * y0;
}


void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
    Euclid(b, a%b, d, x0, y0 );
    x = y0;
    y = x0 - (a/b) * y0;
}


void Euclid(int a, int b, int &d, int &x, int &y )
{
    if ( b == 0 )
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x0, y0;
    Euclid(b, a%b, d, x0, y0 );
    x = y0;
    y = x0 - (a/b) * y0;
}

*/