Cod sursa(job #2679950)

Utilizator SoulSnorterPetre Robert Cristian SoulSnorter Data 2 decembrie 2020 00:07:16
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <iostream>
#include <fstream>

using namespace std;

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

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

int main()
{
    long long int n,a,b,d,c;
    fin >> n;
    for (int i = 0; i < n; i++)
    {
        fin >> a >> b >> d;
        c = d;
        long long 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';
    }
}