Cod sursa(job #2173877)

Utilizator alex_HarryBabalau Alexandru alex_Harry Data 16 martie 2018 09:19:55
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
void euclid(long long a, long long b, long long *d, long long *x, long long *y)
{
    if(b == 0)
    {
        *d = a;
        *x = 1;
        *y = 0;
        return;
    }
    long long x0, y0;
    euclid(b, a % b, d, &x0, &y0);
    *x = y0;
    *y = x0 - (a / b) * y0;
}

int main()
{
    long long T;
    f >> T;
    while(T--)
    {
        long long a, b, c;
        f >> a >> b >> c;
        long long d, x0, y0;
        euclid(a, b, &d, &x0, &y0);
        if(c % d != 0)
        {
            g << "0 0\n";
            continue;
        }
        g << x0 * (c / d) << " " << (y0 * (c / d)) << "\n";
    }
    return 0;
}