Cod sursa(job #2669573)

Utilizator AlexandraMatasaAlexandra Matasa AlexandraMatasa Data 7 noiembrie 2020 11:38:00
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("euclid3.in");
ofstream g("euclid3.out");

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

int main()
{
    int n;
    f >> n;

    for (int t = 1; t <= n; t++)
    {
        int a, b, c;
        int x, y;
        f >> a >> b >> c;
        int d = euclid(a, b, x, y);
        cout << x << ' '  << y << ' '<< d << '\n';
        if (c%d != 0)
            g << "0 0\n";
        else
            g << 1LL * x * c/d << ' ' << 1LL * y * c/d << '\n';
    }

    return 0;
}