Cod sursa(job #2228405)
Utilizator | Data | 3 august 2018 16:24:57 | |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.72 kb |
#include <iostream>
using namespace std;
void extended_gcd(int a,int b,int *d,int *x,int *y)
{
if(b!=0) {
int x0,y0;
extended_gcd(b,a%b,d,&x0,&y0);
*x=y0;
*y=x0-a/b*y0;
}
else {
*d=a;
*x=1;
*y=0;
}
}
int main()
{
freopen("euclid3.in","r",stdin);
freopen("euclid3.out","w",stdout);
int t,i,a,b,c,d,x,y;
scanf("%d",&t);
for(i=0;i<t;i++) {
scanf("%d %d %d",&a,&b,&c);
extended_gcd(a,b,&d,&x,&y);
if(c%d!=0) {
x=0;
y=0;
}
else {
x*=c/d;
y*=c/d;
}
printf("%d %d\n",x,y);
}
return 0;
}