Pagini recente » Cod sursa (job #1653680) | Cod sursa (job #3226294) | Cod sursa (job #3219402) | Cod sursa (job #1146810) | Cod sursa (job #2460154)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
void euclid(int a,int b,int &x0,int &y0,int &d){
if(b == 0){
x0 = 1;
y0 = 0;
d = a;
return;
}
euclid(b,a % b,x0,y0,d);
int x = y0;
int y = x0 - (a / b) * y0;
x0 = x;
y0 = y;
}
int main()
{
int tests;
in>>tests;
for(int i = 1; i <= tests; i++){
int a,b,c;
in>>a>>b>>c;
int x,y,cmmdc;
euclid(a,b,x,y,cmmdc);
if(c % cmmdc != 0)
out<<0<<" "<<0;
else{
if(a * x * c / cmmdc + b * y * c / cmmdc == c)
out<<x * c / cmmdc<<" "<<y * c / cmmdc;
}
out<<"\n";
}
return 0;
}