Cod sursa(job #2974481)

Utilizator hutanuHutanu Andrei hutanu Data 4 februarie 2023 09:54:10
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <fstream>

using namespace std;

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

int t, i, a, b, c, d, x, y;

void euclid(int a, int b, int &d, int &x, int &y)
{
    if(b == 0)
    {
        d = a;
        x = 1;
        y = 1;
    }
    else
    {
        int x0, y0;
        euclid(b, a % b, d, x0, y0);
        x = y0;
        y = x0 - (a / b) * y0;
    }
}

int main()
{
    fin >> t;
    for(i = 1; i <= t; i++)
    {
        fin >> a >> b >> c;
        euclid(a, b, d, x, y);
        ///if(a * x + b * y != c)
        ///    fout << 0 << ' ' << 0 << '\n';
        ///else
            fout << x * (c / d) << ' ' << y * (c / d) << '\n';
    }
    return 0;
}