Pagini recente » Cod sursa (job #287987) | Cod sursa (job #2294832) | Cod sursa (job #654002) | Cod sursa (job #1769302) | Cod sursa (job #933866)
Cod sursa(job #933866)
#include<fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int n, a, b, d, x, y;
void euclid(int a, int b, int &x, int &y, int &d)
{
int xx, yy, q;
if(b == 0){
d = a;
x = 1;
y = 0;
return;
}
q = a/b;
euclid(b, a%b, xx, yy, d);
x = yy;
y = xx - q*yy;
}
int main()
{
int i, c;
fin >> n;
for(i=0; i<n; ++i){
fin >> a >> b >> c;
euclid(a, b, x, y, d);
if(c%d != 0)
fout << 0 << " " << 0 << "\n";
else{
int q = c/d;
fout << x*q << " " << y*q << "\n";
}
}
fin.close();
fout.close();
return 0;
}