Cod sursa(job #2461865)

Utilizator hurjui12AlexandruHurjui Alexandru-Mihai hurjui12Alexandru Data 26 septembrie 2019 12:37:39
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>
using namespace std;

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

int euclid(int a, int b, int &x, int &y)
{
    if (b == 0)
    {
        //adica e gata cmmdc-ul
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        int x0, y0;
        int val = euclid(b, a%b, x0, y0);
        x = y0;
        y = x0 - (a/b)*y0;
        return val;
    }
}

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