Cod sursa(job #240933)
Utilizator | Data | 8 ianuarie 2009 22:02:29 | |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.58 kb |
#include <stdio.h>
long a,b,c,t,d,x,y;
void euclid(long a, long b, long &d, long &x, long &y)
{
long x0, y0;
if (b==0) {
d=a;
x=1;
y=0;
} else {
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);
scanf("%ld",&t);
for (;t;--t){
scanf("%ld %ld %ld",&a,&b,&c);
euclid(a,b,d,x,y);
if (c%d==0)printf("%ld %ld\n",x*(c/d),y*(c/d));
else printf("0 0\n");
}
return 0;
}