Cod sursa(job #1849161)

Utilizator zdavid112zIon David-Gabriel zdavid112z Data 17 ianuarie 2017 08:48:39
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.69 kb
#include <cstdio>

using namespace std;

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

int main()
{
    int com, a, b, d, x, y, c;
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);
    scanf("%d", &com);
    while(com--)
    {
        scanf("%d%d%d", &a, &b, &c);
        euclidEx(a, b, d, x, y);
        if(c % d != 0)
            printf("0 0\n");
        else printf("%d %d\n", x * (c / d), y * (c / d));
    }
    return 0;
}