Cod sursa(job #2749230)

Utilizator richardbaczur1Baczur Richard richardbaczur1 Data 5 mai 2021 22:36:42
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.8 kb
#include <fstream>
#define infile "euclid3.in"
#define outfile "euclid3.out"

using namespace std;

ifstream f(infile);
ofstream g(outfile);
unsigned int t;

inline int gcd_extins(int a, int b, int& x, int& y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }

    int x1, y1;
    int d = gcd_extins(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

int main()
{
    f >> t;

    while (t--)
    {
        int a, b, c;
        f >> a >> b >> c;

        int x, y, d;
        d = gcd_extins(a, b, x, y);

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

    f.close();
    g.close();
    return 0;
}