Cod sursa(job #1800471)

Utilizator msciSergiu Marin msci Data 7 noiembrie 2016 19:59:11
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;

int euclid_extended(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    } else {
        int x0, y0;
        int d = euclid_extended(b, a % b, x0, y0);
        x = y0;
        y = x0 - (a / b) * y0;
        return d;
    }
}

int main() {
#ifndef DEBUG
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);
#endif

    int T; scanf("%d", &T);
    for (int tt = 0; tt < T; tt++) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        int x, y;
        int ans = euclid_extended(a, b, x, y);
        if (c % ans == 0) {
            printf("%d %d\n", x * (c / ans), y * (c / ans));
        } else {
            printf("0 0\n");
        }
    }
}