Cod sursa(job #2637410)

Utilizator zarg169Roxana zarg169 Data 22 iulie 2020 20:35:15
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
#include <iostream>
#include <fstream>

using namespace std;

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 {
        euclid(b, a % b, d, x, y);
        long long newX = y;
        long long newY = x - y * (a/b);
        x = newX;
        y = newY;
    }
}

int main()
{

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

    int t;
    fin >> t;

    for (int test = 1; test <= t ; ++test) {
        long long a, b, c, d, x, y;
        fin >> a >> b >> c;

        euclid(a, b, d, x, y);
        if (c % d) {
            fout << "0 " << "0 " << "\n";
        } else {
            fout << x * (c/d) << " " << y * (c/d) << "\n";
        }
    }
    return 0;
}