Cod sursa(job #789643)

Utilizator beldeabogdanBogdan Beldea beldeabogdan Data 18 septembrie 2012 20:05:40
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <cstdio>

void euclid(long long a,long long b,long long &d,long long &x,long long &y){
    if(b == 0) {
        d = a;
        x = 1;
        y = 0;
        return;
    }
	long long x0,y0;
	euclid(b,a%b,d,x0,y0);
	x = y0;
	y = x0 - (a/b)*y0;
}

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