Cod sursa(job #2674635)

Utilizator George_CristianGeorge Dan-Cristian George_Cristian Data 19 noiembrie 2020 18:56:07
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <cstdio>
#include <iostream>

using namespace std;

void euclid_extins(long long a, long long b, long long &d, long long &x, long long &y) {
    if (!b) {
        x = 1;
        y = 0;
        d = a;
        return;
    }
    long long x1, y1;
    euclid_extins(b, a % b, d, x1, y1);
    x = y1;
    y = x1 - (a / b) * y1;
}

int main() {
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);
    long long n, a, b, c;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%lld%lld%lld", &a, &b, &c);
        long long d, x, y;
        euclid_extins(a, b, d, x, y);
        if (c % d)
            printf("0 0\n");
        else
            printf("%lld %lld\n", x * c / d, y * c / d);
    }
    return 0;
}