Cod sursa(job #143432)
Utilizator | MciprianM MciprianM | Data | 26 februarie 2008 15:34:57 |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include<fstream>
using namespace std;
void Euclidextins(long a,long b, long*d, long *x, long*y){
if(b==0){
*d=a;
*x=1;
*y=0;
}
else{
long x0,y0;
Euclidextins(b,a%b,d,&x0,&y0);
*x=y0;
*y=x0-(a/b)*y0;
}
}
int main(){
long t, i,x,y,d,a,b,c;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
f>>t;
for(i=0;i<t;i++){
f>>a>>b>>c;
Euclidextins(a,b,d,x,y);
if(c%d) g<<"0 0 \n";
else g<<(c/d)*x<<' '<<(c/d)*y<<'\n';
}
f.close();
g.close();
return 0;
}