Cod sursa(job #1483806)

Utilizator R4DIC4LTeodorescu Oana Maria R4DIC4L Data 9 septembrie 2015 22:28:53
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>
using namespace std;

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

int gcd(int a, int b, int &x, int &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }

    int x0, y0, d;
    d = gcd(b, a % b, x0, y0);
    x = y0;
    y = x0 - (a / b)*y0;
    return d;
}

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

    in >> t;

    while (t--)
    {
        in >> a >> b >> c;
        int x, y;
        int d = gcd(a, b, x, y);
        if (c % d == 0)
        {
            out << x*(c / d) << " " << y*(c / d) << "\n";
        }
        else
        {
            out << "0 0\n";
        }
    }
    return 0;
}