Cod sursa(job #779260)

Utilizator NexflameGeorge Pultea Nexflame Data 17 august 2012 11:53:15
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <iostream>
#include <fstream>
using namespace std;

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

}

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

    int t;
    in >> t;

    for (int i = 0; i < t; i++)
    {
        int x = 0, y = 0, a, b, c, d;
        in >>a >> b >> c;
        euclid(a, b, d, x, y);

        if (c % d == 0)
        {
            x = x * (c / d) ;
            y = y * (c / d) ;
        }
        else
            x = 0, y = 0;

        out << x << " " << y << '\n';
    }

    return 0;
}