Cod sursa(job #3264550)

Utilizator Andercau_VasileAndercau Vasile Andercau_Vasile Data 22 decembrie 2024 13:24:07
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <fstream>
using namespace std;

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

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

int main() {
    int t;
    fin >> t;
    while (t--) {
        int a, b, c;
        fin >> a >> b >> c;

        int d;
        int x, y;
        euclid(a, b, d, x, y);
        if (c % d) {
            fout << 0 << ' ' << 0 << '\n';
        } else {
            fout << x * (c / d) << ' ' << y * (c / d) << '\n';
        }
    }
    return 0;
}