Cod sursa(job #2595998)

Utilizator AlexVulpoiuAlexandru Vulpoiu AlexVulpoiu Data 8 aprilie 2020 22:17:10
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>
#include <algorithm>

using namespace std;

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

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

int euclid_extins(int a, int b, int &x, int &y)
{
    int d, x0, y0;

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

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

        d = euclid_extins(a, b, x, y);

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

        t--;
    }

    f.close();
    g.close();

    return 0;
}