Cod sursa(job #2453864)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 6 septembrie 2019 12:41:24
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <unordered_map>

using namespace std;

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() {
    ios_base::sync_with_stdio(false);

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

    int T;
    in >> T;

    while (T--){
        int a, b, c;
        in >> a >> b >> c;

        int d, x, y;
        euclid(a, b, d, x, y);

        if (c % d){
            out << "0 0\n";
        } else {
            out << x * c / d << " " << y * c / d << "\n";
        }
    }

    return 0;
}