Cod sursa(job #2679949)

Utilizator SoulSnorterPetre Robert Cristian SoulSnorter Data 2 decembrie 2020 00:05:17
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 fin("euclid3.in");
ofstream fout("euclid3.out");

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

int main()
{
    int n,a,b,d,c;
    fin >> n;
    for (int i = 0; i < n; i++)
    {
        fin >> a >> b >> d;
        c = d;
        int x, y;
        euclid(a, b, &d, &x, &y);
        if (a * (x * c / d) + b * (y * c / d) != c)
            fout << '0' << " " << '0' << '\n';
        else
            fout << x * c / d << " " << y * c / d << '\n';
    }
}