Pagini recente » Cod sursa (job #186740) | Cod sursa (job #408380) | Cod sursa (job #1766830) | Cod sursa (job #1536485) | Cod sursa (job #2830943)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
void euclid_ext(int a,int b, int &d, int &x, int &y)
{
if(b==0)
{
d = a;
x = 1, y = 1;
}
else
{
int x1,y1;
euclid_ext(b, a%b, d, x1, y1);
// cout<<x1<<" "<<y1<<" "<<d<<" "<<"\n";
x = y1;
y = x1 - a/b * y1;
}
}
int main()
{
int nr;
f>>nr;
for(int i = 1; i <= nr; i++)
{
int a,b,c,d;
f>>a>>b>>c;
int x,y;
euclid_ext(a,b,d,x,y);
if(c%d)
g<<0<<" "<<0<<"\n";
else
g<<x<<" "<<y<<"\n";
}
return 0;
}