Cod sursa(job #1661570)

Utilizator NineshadowCarapcea Antonio Nineshadow Data 23 martie 2016 23:10:01
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <fstream>
std::ifstream in("euclid3.in");
std::ofstream out("euclid3.out");
using _l = long long;
void euclid(_l a, _l b, _l *d, _l *x, _l *y)
{
    if (b == 0) {
        *d = a;
        *x = 1;
        *y = 0;
    } else {
        _l x0, y0;
        euclid(b, a % b, d, &x0, &y0);
        *x = y0;
        *y = x0 - (a / b) * y0;
    }
}
int main()
{
    _l n , a , b , c, x , y, d;
    in >> n;
    for(int i = 0; i < n; ++i)
    {
        in >> a >> b >> c;
        euclid(a,b,&d,&x,&y);
        if(c%d)
            out << "0 0\n";
        else
            out << x*c/d << ' ' << y*c/d << '\n';
    }

    return 0;
}