Pagini recente » Cod sursa (job #2310892) | Cod sursa (job #227611) | Cod sursa (job #830342) | Cod sursa (job #2915822) | Cod sursa (job #1066113)
#include <fstream>
using namespace std;
class eq{
public:
int a, b, res;
eq(){};
eq(int a1, int b1, int res1){
a = a1;
b = b1;
res = res1;
}
eq operator %(eq other){
int t = res / other.res;
eq ans(a - t * other.a, b - t* other.b, res % other.res);
return ans;
}
};
eq gcd(eq x, eq y){
eq z;
while(y.res){
z = x;
x = y;
y = z % y;
}
return x;
}
int main(){
ifstream in("euclid3.in");
ofstream out("euclid3.out");
int t;
in >> t;
while(t--){
int x, y, z;
in >> x >> y >> z;
eq a(x, 0, x), b(0, y, y);
eq ans = gcd(a, b);
if(z % ans.res != 0){
out << "0 0 \n";
continue;
}
out << ans.a / x * z / ans.res << " " << ans.b / y * z / ans.res << "\n";
}
return 0;
}