Mai intai trebuie sa te autentifici.
Cod sursa(job #520911)
Utilizator | Data | 10 ianuarie 2011 19:09:06 | |
---|---|---|---|
Problema | Algoritmul lui Euclid extins | Scor | 70 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.99 kb |
#include <cstdio>
using namespace std;
long long x, y, z,
a, b, d,
rev;
long long stck[1024];
int size = 0;
int pop()
{
size--;
return stck[size];
}
void push(int x)
{
stck[size] = x;
size++;
}
void euclid_cmmdc()
{
while ((x != 0)&&(y != 0))
{
push(x/y);
d = y;
y = x % y;
x = d;
}
d = x + y;
if (z % d == 0)
{
z = z / d;
a = 1;
b = 1;
while(size)
{
x = b;
y = a - pop() * b;
a = x;
b = y;
}
if (rev)
printf("%lld %lld\n", b*z, a*z);
else
printf("%lld %lld\n", a*z, b*z);
}
else
{
printf("0 0\n");
size = 0;
}
}
int main()
{
int nr;
freopen("euclid3.in", "r", stdin);
freopen("euclid3.out", "w", stdout);
scanf("%d", &nr);
while(nr--)
{
scanf("%lld %lld %lld", &x, &y, &z);
euclid_cmmdc();
}
return 0;
}