Cod sursa(job #2715565)

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

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

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

int main()
{

    long long n, a, b, x, y, d, c;
    f >> n;
    for (long long 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";
    }
}