Cod sursa(job #2989094)

Utilizator oana75Ioana Prunaru oana75 Data 5 martie 2023 21:12:06
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
#include <iostream>
#include <fstream>

using namespace std;

int T, a, b, c;

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

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

int main()
{
    in >> T;
    for(int i = 1; i <= T; i++)
    {
        int x, y, d;
        in >> a >> b >> c;
        euclid_extins(a, b, d, x, y);
        if(c % d != 0)
            out << 0 << " " << 0 << '\n';
        else
            out << x * (c / d) << " " << y * (c / d) << '\n';
    }
    in.close();
    out.close();
    return 0;
}