Cod sursa(job #2048149)

Utilizator zanugMatyas Gergely zanug Data 25 octombrie 2017 19:37:25
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n;

void eucex(int a, int b, int& x, int& y, int& d)
{
    if(!b)
    {
        d = a;
        x = 1;
        y = 0;
    }
    else
    {
        int xx, yy;
        eucex(b, a%b, xx, yy, /*??*/d);
        x = yy;
        y = xx - (a / b) * yy;
    }
}

int main()
{
    ios::sync_with_stdio(false);

    fin >> n;

    while(n--)
    {
        int a, b, c;
        fin >> a >> b >> c;

        int x, y, d;
        //cout << x << " " << y << " " << d << "\n";
        eucex(a, b, x, y, d);
        //cout << x << " " << y << " " << d << "\n";

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

    return 0;
}