Cod sursa(job #2470781)

Utilizator hax_m8Nicolae Antonio Cristian hax_m8 Data 9 octombrie 2019 18:53:51
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda basic_stuff Marime 0.72 kb
#include <fstream>

using namespace std;

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

int euclext(int a, int b, int c, int &x, int &y)
{
    int q[50], x0, y0, r, pos = 0;
    while(b)
    {
        q[++pos] = a / b;
        r = a % b;
        a = b;
        b = r;
    }
    if(c % a) {x=y=0;return 0;}
    x0 = c / a;
    y0 = 0;
    while(pos)
    {
        x = y0;
        y = x0 - q[pos--] * y0;
        x0 = x;
        y0 = y;
    }
    return 1;
}

int main()
{
    int t;
    fin >> t;
    for(int i = 0; i < t; i++)
    {
        int a, b, c, x, y;
        fin >> a >> b >> c;
        euclext(a, b, c, x, y);
        fout << x << " " << y << "\n";
    }
    return 0;
}