Cod sursa(job #2715560)

Utilizator LawrentiuTirisi Claudiu Lawrentiu Data 3 martie 2021 20:58:19
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.76 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream o("euclid3.out");

int euclid(int a, int b, int *x, int *y)
{

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

int main()
{

    int n, a, b, x, y, d, c;
    f >> n;
    for (int i = 0; i < n; i++)
    {
        f >> a >> b >> c;
        d = euclid(a, b, &x, &y);
        cout << x << " " << y << " " << c << " " << d << "\n";
        if (c % d != 0)
            o << "0 0";
        else
            o << x * c / d << " " << y * c / d;
        o << "\n";
    }
}