Pagini recente » Cod sursa (job #2134735) | Cod sursa (job #1815019) | Cod sursa (job #3130699) | Cod sursa (job #573658) | Cod sursa (job #2257846)
#include <fstream>
#include <climits>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int t,x,y;
void eucleed (int a,int b,int c);
void citire()
{fin>>t;
int i,a,b,c;
for(i = 1; i <= t; i++)
{fin>>a>>b>>c;
eucleed(a,b,c);
if( x == INT_MIN || y == INT_MIN)
fout<<"0 0"<<'\n';
else
fout<<x<<' '<<y<<'\n';
}
}
void eucleed (int a, int b, int c)
{ x = y = INT_MIN;
int x0 = 1, y0 = 0, x1 = 0, y1 = 1,r;
while(b)
{r = a%b;
c = a / b;
a = b;
b = r;
x = x0 - c * x1;
x0 = x1;
x1 = x;
y = y0 - c * y1;
y0 = y1;
y1 = y;
}
}
int main()
{
citire();
fin.close();
fout.close();
return 0;
}