Pagini recente » Cod sursa (job #3316159) | Cod sursa (job #3350976) | Cod sursa (job #3312832) | Cod sursa (job #2945923) | Cod sursa (job #3356720)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int main(){
long long y0 = 0, y1 = 1;
long long x0 = 1, x1 = 0;
long long a, b, c, d;
long long r, q, y, x;
int t;
fin >> t;
for(int i = 0; i < t; i++){
fin >> a >> b >> c;
long long aa = a, bb = b;
a = abs(a);
b = abs(b);
while (b != 0)
{
r = a % b;
q = a / b;
a = b;
b = r;
x = x0 - q * x1;
y = y0 - q * y1;
y0 = y1; x0 = x1;
y1 = y; x1 = x;
cout << a << " " << b << " ";
cout << q << " " << r << " ";
cout << y1 << " " << y0 << endl;
}
d = a;
if(c % d == 0){
if(aa < 0){
x0 = -x0;
}
if(bb < 0){
y0 = -y0;
}
fout << x0 * (c / d) << " " << y0 * (c/d)<< endl;
}
else{
fout << 0 << " " << 0 << endl;
}
}
fin.close();
fout.close();
return 0;
}