Cod sursa(job #3294815)

Utilizator Dragos_MatuDragos Gabriel Matu Dragos_Matu Data 29 aprilie 2025 00:06:31
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <iostream>
#include <fstream>
#include <cstdlib>
// #define mod 666013
using namespace std;

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
unsigned long long i, j;

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

int main()
{
    unsigned int T;
    long long a, b, c, d, x, y;
    fin >> T;
    while (T > 0)
    {
        fin >> a >> b >> c;
        euclid(a, b, &d, &x, &y);
        if (c % d)
            fout << "0 0" << endl;
        else
            fout << x * (c / d) << " " << y * (c / d) << endl;
        T--;
    }

    return 0;
}