Cod sursa(job #2710737)

Utilizator IulianOleniucIulian Oleniuc IulianOleniuc Data 22 februarie 2021 22:34:52
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <bits/stdc++.h>
using namespace std;

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

int main() {
    int t; fin >> t;
    while (t--) {
        int a, b, c; fin >> a >> b >> c;
        int xa = 1, ya = 0, xb = 0, yb = 1;
        while (b) {
            int q = a / b;
            int r = a % b;
            a = b;
            b = r;
            int xr = xa - q * xb;
            int yr = ya - q * yb;
            xa = xb; ya = yb;
            xb = xr; yb = yr;
        }
        if (c % a)
            fout << "0 0\n";
        else
            fout << c / a * xa << ' ' << c / a * ya << '\n';
    }
    return 0;
}