Cod sursa(job #2024854)

Utilizator S4lexandruAlexandru Stefanica S4lexandru Data 21 septembrie 2017 12:45:56
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <fstream>


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

    int x0, y0;
    int d = solve_eq(b, a % b, x0, y0);

    x = y0;
    y = x0 - (a / b) * y0;

    return d;
}

int main()
{
    std::ifstream in{"euclid3.in"};
    std::ofstream out{"euclid3.out"};

    int a, b, c, T;

    for (in >> T; T; --T) 
    {
        in >> a >> b >> c;
        
        int x, y, d;
        d = solve_eq (a, b, x, y);


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