Cod sursa(job #2754316)

Utilizator bogdan_modoleaBogdan Modolea bogdan_modolea Data 25 mai 2021 16:50:05
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};

const string file = "euclid3";

ifstream fin(file + ".in");
ofstream fout(file + ".out");

int q, a, b, c, d;

int euclid(int a, int b, int &x, int &y) {
    if (!b) {
        x = 1;
        y = 0;
        return a;
    }
    int x0, y0, d;
    d = euclid(b, a % b, x0, y0);
    x = y0;
    y = x0 - (a / b) * y0;
    return d;
}

int main() {
    int x, y;
    fin >> q;
    while (q--) {
        fin >> a >> b >> c;
        d = euclid(a, b, x, y);
        if (c % d == 0)
            fout << x * (c / d) << " " << y * (c / d) << "\n";
        else fout << "0 0\n";
    }
    return 0;
}