Cod sursa(job #879495)

Utilizator vgabi94Vaduva Gabriel vgabi94 Data 15 februarie 2013 15:10:06
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <fstream>
using namespace std;

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

void 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()
{
    int a, b, c, t, d, x, y;
    in >> t;
    for (int i = 0; i < t; i++)
    {
        in >> a >> b >> c;
        euclid(a, b, d, x, y);
        if (c % d == 0) out << (c / d) * x << ' ' << (c / d) * y << '\n';
        else out << 0 << ' ' << 0 << '\n';
    }
    return 0;
}