Cod sursa(job #1414362)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 2 aprilie 2015 15:58:07
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <bits/stdc++.h>

using namespace std;

void gcd(int a, int b, int &x0, int &y0, int &d)
{
    if (!b)
    {
        x0 = 1;
        y0 = 0;
        d = a;
    }
    else
    {
        int x, y;
        gcd(b, a % b, x, y, d);

        x0 = y;
        y0 = x - (a / b) * y;
    }
}

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

    int T, x, t;

    in >> T;

    while (T--)
    {
        int a, b, c, d, x, y;
        in >> a >> b >> c;

        gcd(a, b, x, y, d);

        if (c % d)
            out << "0 0\n";
        else
            out << x * (c / d) << " " << y * (c / d)  << "\n";
    }

    return 0;
}