Cod sursa(job #2334880)

Utilizator andra_moldovanAndra Moldovan andra_moldovan Data 3 februarie 2019 11:56:17
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
#include <fstream>

using namespace std;

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

inline int Euclid(int a, int b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    else {
        long long x1, y1;
        int d = Euclid(b, a % b, x1, y1);
        x = y1;
        y = x1 - (a / b) * y1;
        return d;
    }
}

inline void Read() {
    int N, x, y, c, d;
    long long xx, yy;

    fin >> N;

    while (N--) {
        fin >> x >> y >> c;

        d = Euclid(x, y, xx, yy);
        if (c % d != 0) {
            fout << "0 0" << "\n";
            continue;
        }
        fout << xx * c / d << " " << yy * c / d << "\n";
    }
}

int main () {
    Read();

    fin.close(); fout.close(); return 0;
}