Cod sursa(job #3240878)

Utilizator AlbertPavPavalache Albert AlbertPav Data 22 august 2024 12:40:23
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>

using namespace std;

ifstream f("euclid3.in");
ofstream g("euclid3.out");

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

int main()
{
    int T, a, b, c, d, x, y, k;
    f >> T;
    while(T--)
    {
        f >> a >> b >> c;
        EuclidExtins(a, b, d, x, y);
        if(c != d)
            g << "0 0\n";
        else
        {
            k = c / d;
            x *= k;
            y *= k;
            g << x << ' ' << y << '\n';
        }
    }
    f.close();
    g.close();
    return 0;
}