Cod sursa(job #2615162)

Utilizator MocalinnoMoca Andrei Catalin Mocalinno Data 13 mai 2020 19:07:32
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <bits/stdc++.h>
#define DAU  ios_base::sync_with_stdio(false); fin.tie(0); fout.tie(0);
#define PLEC fin.close(); fout.close(); return 0;
using namespace std;
const string problem("euclid3");
ifstream fin(problem + ".in");
ofstream fout(problem + ".out");
inline int Euclid(int a, int b, int& x, int& y) {
    if (!b) {
        x = 1, y = 0;
        return a;
    }
    int x0, y0, d = Euclid(b, a % b, x0, y0);
    x = y0, y = x0 - (a / b) * y0;
    return d;
}
int t, a, b, c, d, x, y;
int main() {
    DAU
    fin >> t;
    while (t--) {
        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";
    }
    PLEC
}