Cod sursa(job #622551)
Utilizator | Data | 18 octombrie 2011 09:00:35 | |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.61 kb |
#include<stdio.h>
void euclid(int a,int b,int &x,int &y , int &d)
{
if(b==0)
{
x=1;
y=0;
d=a;
return;
}
int x1 , y1 , q=a/b;
euclid(b,a%b,x1,y1,d);
x=y1;
y=x1-q*y1;
}
int main()
{
int n , i , a , b , c , x , y , d , p;
freopen("euclid3.in","r",stdin);
freopen("euclid3.out","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&a,&b,&c);
euclid(a,b,x,y,d);
p=c/d;
if(c%d!=0)
printf("0 0\n");
else
printf("%d %d\n",p*x,p*y);
}
}