Cod sursa(job #3217710)

Utilizator DobraVictorDobra Victor Ioan DobraVictor Data 24 martie 2024 13:37:09
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <iostream>
#include <fstream>
#include <stdint.h>

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

int main() {
    std::ifstream fin("euclid3.in");
    std::ofstream fout("euclid3.out");

    int64_t t;
    fin >> t;

    for(int64_t i = 0; i != t; ++i) {
        int64_t a, b, c;
        fin >> a >> b >> c;

        int64_t d, x, y;
        Euclid(a, b, d, x, y);

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

    fin.close();
    fout.close();

    return 0;
}