Cod sursa(job #3202905)

Utilizator indianu_talpa_iuteTisca Catalin indianu_talpa_iute Data 12 februarie 2024 16:50:02
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <bits/stdc++.h>

using namespace std;

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

int xlcd(int a, int b, int& x, int& y) {
    if (!b) {
        x = 1;
        y = 0;
        return a;
    }

    int x0, y0;
    int lcd = xlcd(b, a % b, x0, y0);
    x = y0;
    y = x0 - a / b  * x;
    return lcd;
}

void solve() {
    int a, b, c, x, y;
    fin >> a >> b >> c;

    int lcd = xlcd(a, b, x, y);
    if (c % lcd) {
        fout << 0 << ' ' << 0 << '\n';
    } else
        fout << x * (c / lcd) << ' ' << y * (c / lcd) << '\n';
}

int main() {
    int t;
    fin >> t;
    for (int i = 0; i < t; i++)
        solve();
    return 0;
}