Cod sursa(job #1221113)

Utilizator EpictetStamatin Cristian Epictet Data 19 august 2014 16:01:17
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int T, a, b, c, x, y, cmmdc, V[10000];

void PreCalcul(int aa, int bb)
{
    int rr;
    while (bb)
    {
        V[++V[0]] = aa / bb;
        rr = aa % bb;
        aa = bb;
        bb = rr;
    }
    cmmdc = aa;
}

void Solve()
{
    while (V[0])
    {
        int aux = x;
        x = y;
        y = aux - V[V[0]] * y;
        V[0]--;
    }
}

int main()
{
    fin >> T;
    for (int i=1; i<=T; i++)
    {
        fin >> a >> b >> c;
        PreCalcul(a, b);
        x = 1;
        y = 0;
        Solve();
        if (c % cmmdc)
        {
            fout << 0 << ' ' << 0 << '\n';
        }
        else
        {
            fout << x * (c / cmmdc) << ' ' << y * (c / cmmdc) << '\n';
        }
    }

    fout.close();
    return 0;
}