Cod sursa(job #1814352)

Utilizator BourucLiviuBouruc Petru Liviu BourucLiviu Data 23 noiembrie 2016 21:26:23
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include <cstdio>

using namespace std;

int aee(int a, int b, int &x, int &y) /// x0, y0 - param de transef, mobili, care pot reprezenta oricand o sol, cu ajutorur carora se calculeaza x si y
{
    if(!b)
    {
        x = 1;
        y = 0;
        return a;
    }
    int x0, y0, d;
    d = aee(b, a % b, x0, y0);
    x = y0;
    y = x0 - (a / b) * y0;
    return d;
}

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