Cod sursa(job #2481400)

Utilizator hurjui12AlexandruHurjui Alexandru-Mihai hurjui12Alexandru Data 26 octombrie 2019 20:36:00
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <fstream>
using namespace std;

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

typedef long long mare;

void euclid(int a, int b, int &d, mare &x, mare &y)
{
    if (b == 0)
    {
        d = a;
        x = 1;
        y = 0;
    }
    else
    {
        mare x0, y0;
        euclid(b, a%b, d, x0, y0);
        x = y0;
        y = x0 - a/b * y0;
    }
}

int main()
{
    int t, a, b, c, i;
    int gcd;
    mare solx, soly;
    fin >> t;
    for (i = 1; i<=t; i++)
    {
        fin >> a >> b >> c;
        euclid(a, b, gcd, solx, soly);
        if (c % gcd == 0)
            fout << solx * c/gcd << ' ' << soly * c/gcd << '\n';
        else
            fout << "0 0\n";
    }
    return 0;
}