Cod sursa(job #2879269)

Utilizator Tudose_StefanTudose Alexandru Stefan Tudose_Stefan Data 28 martie 2022 12:58:47
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <fstream>
#include <iostream>

using namespace std;

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

int nrec, a, b, c, divizor, x, y;

void euclidnorm(int a, int b, int *d)
{
    if (b == 0)
        *d = a;
    else
        euclidnorm(b, a%b, d);
}

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

int main()
{
    fin >> nrec;
    while (nrec)
    {

        fin >> a >> b >> c;
        euclidex(a, b, &divizor, &x, &y);
        if (c % divizor != 0)
            fout << 0 << ' ' << 0 << '\n';
        else
        {
            fout << 1LL * x * c/divizor << ' ' << 1LL * y* c/divizor << '\n';
        }
        nrec--;
    }
    return 0;
}