Mai intai trebuie sa te autentifici.
Cod sursa(job #982371)
| Utilizator | Data | 9 august 2013 02:05:26 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid extins | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 1.13 kb |
#include <iostream>
#include <fstream>
using namespace std;
void euclid_extins(int a, int b, int*x , int *y)
{
if (b == 0) {
printf ("intra aici");
printf (" b = 0 ; x = %i, y = %i", *x,*y);
*x = 1; *y = 0;
}
else { printf(" x = %i, y = %i \n", *x, *y);
euclid_extins ( b, a%b, x , y);
int z = *y, t = *x;
*x = z;
*y = t - (a/b) * z;
}
}
void euclid ( int a,int b,int *d )
{
if ( b == 0 ) {
*d = a;
}
else euclid ( b , a%b, d);
}
int main()
{
ifstream in("euclid3.in");
ofstream out("euclid3.out");
int n;
in >> n;
int a,b,c,i,d=0,x,y;
for (i=0; i < n; i++)
{
in >> a >> b >> c;
euclid ( a,b,&d);
if ( c % d == 0) {
x=0;y=0;
euclid_extins(a,b,&x,&y);
x = c/d * x;
y = c/d * y;
out << x << " " << y << "\n";
}
else out << "0 0\n";
}
in.close();
out.close();
system("pause");
return 0;
}
