Cod sursa(job #3250634)

Utilizator Radu_Tanasebitlevel Radu_Tanase Data 22 octombrie 2024 16:10:23
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <fstream>

using namespace std;

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

void euclid_extins(int a, int b, int &d, int &x, int &y)
{
    if (!b)
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x1, y1;
    euclid_extins(b, a % b, d, x1, y1);
    x = y1;
    y = x1 - (a / b) * y1;
}

int main()
{
    int a, b, c, t, x, y, d;
    fin >> t;
    while (t > 0)
    {
        fin >> a >> b >> c;
        x = y = d = 0;
        euclid_extins(a, b, d, x, y);
        if((c % d) != 0)
            fout << "0 0" << '\n';
        else
            fout << x * (c / d) << ' ' << y * (c / d) << '\n';
    }
    return 0;
}