Pagini recente » Cod sursa (job #127195) | Rating zbranca lorin (zbrancalorin) | Cod sursa (job #256299) | Cod sursa (job #2553050) | Cod sursa (job #1896106)
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin;
ofstream fout;
void euclidExtins(long long a,long b,long long& d,long long& x,long long& y)
{
if(b == 0)
{
d=a;
x=1;
y=0;
}
else
{
long long x0,y0;
euclidExtins(b,a%b,d,x0,y0);
x=y0;
y=x0-(a/b)*y0;
//cout<<x<<' '<<y;
//cout<<'\n';
}
}
int main()
{
ios_base::sync_with_stdio(false);
long long x=0,y=0,d=0;
int n;
fin.open("euclid3.in");
fout.open("euclid3.out");
fin>>n;
for(int i = 0; i < n; ++i)
{
x=y=d=0;
long long a,b,c;
fin>>a>>b>>c;
euclidExtins(a,b,d,x,y);
if(c%d == 0)
{
fout<<x<<' '<<y;
}
else
{
fout<<(x*(c/d))<<' '<<(y*(c/d));
}
fout<<'\n';
}
fin.close();
fout.close();
return 0;
}