Cod sursa(job #1963013)

Utilizator antanaAntonia Boca antana Data 12 aprilie 2017 11:08:04
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

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

    int x0, y0;
    euclid(b, a%b, d, x0, y0);
    x = y0;
    y = x0 - (a/b)*y0;
}

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

    int t, a, b, x, y, c, d;

    scanf("%d", &t);
    while(t--) {
        scanf("%d%d%d", &a, &b, &c);
        euclid(a, b, d, x, y);
        if(c % d != 0)
            printf("0 0\n");
        else
            printf("%lld %lld\n", 1LL * x * c/d, 1LL * y*c/d);
    }

    return 0;
}