Cod sursa(job #2917136)

Utilizator papixDoomBanica Cosmin papixDoom Data 3 august 2022 15:11:15
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <stdio.h>
#include <vector>

using namespace std;

int gcd(int a, int b, int &x, int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }

    int d, x_0, y_0;
	
	d = gcd(b, a % b, x_0, y_0);
	x = y_0;
	y = x_0 - (a / b) * y_0;
	
	return d;
}

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

    int t;
    scanf("%d", &t);

    for (int i = 0; i < t; i++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);

        int d, x, y;

        d = gcd(a, b, x, y);

        if (c % d == 0) {
            printf("%d %d\n", x *(c / d), y * (c / d));
        } else {
            printf("0 0\n");
        }
    }

    return 0;
}