Cod sursa(job #2873444)

Utilizator indianu_talpa_iuteTisca Catalin indianu_talpa_iute Data 19 martie 2022 10:32:50
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>
#define LL long long

using namespace std;

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

LL euclid(LL a, LL b, LL &x, LL &y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    LL auxx, auxy, res;
    res = euclid(b, a % b, auxx, auxy);
    x = auxy, y = auxx - (a / b) * auxy;
    return res;
}

int main() {
    int t;
    fin >> t;
    for (int i = 0; i < t; i++) {
        LL a, b, c, x, y, res;
        fin >> a >> b >> c;
        res = euclid(a, b, x, y);
        if (c % res != 0)
            fout << 0 << ' ' << 0 << '\n';
        else
            fout << x * (c / res) << ' ' << y * (c / res) << '\n';
    }
    return 0;
}