Pagini recente » Cod sursa (job #1582363) | Cod sursa (job #198919) | Cod sursa (job #2616060) | Cod sursa (job #2557039) | Cod sursa (job #2470780)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int eucl_ext(int a, int b, int c, int &x, int &y)
{
int q[100], x0, y0, r, pas = 0;
while(b)
{
q[++pas]=a/b;
r=a%b;
a=b;
b=r;
}
if(c%a)
{
x=y=0;
return 0;
}
x = x0 = c/a;
y = y0 = 0;
while(pas)
{
x = y0;
y = x0 - q[pas--]*y0;
x0 = x;
y0 = y;
}
return 1;
}
int main()
{
int a, b, c, x, y, n;
f>> n;
while(n)
{
f >> a >> b >> c;
int e = eucl_ext(a,b,c,x,y);
if(e==1)
g << x << ' ' << y << '\n';
else
g << 0 << ' ' << 0 << '\n';
n--;
}
return 0;
}