Cod sursa(job #2000541)

Utilizator sfechisalin@yahoo.comSfechis Alin [email protected] Data 14 iulie 2017 01:00:52
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>

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

void euclid3(int a, int &x, int b, int &y, int c)
{
    if (b == 0)
    {
        if (c % a)
        {
            x = 0;
            y = 0;
            return;
        }
        x = c / a;
        y = 0;
    }
    else
    {
        int x0, y0;
        euclid3(b, x0, a % b, y0, c);
        x = y0;
        y = x0 - a / b * y0;
    }
}

int main()
{
    int T, a, b, c, x, y;

    fin >> T;

    while (T--)
    {
        fin >> a >> b >> c;
        euclid3(a, x, b, y, c);
        fout << x << " " << y << "\n";
    }

    return 0;
}