Question
Coding problem - 1
You are given three distinct positive integers X,Y,X,Y, and ZZ. Your task is to find integers AA and BB such that:
- BB is equal to one of the three given numbers;
- AA is equal to the product of remaining two numbers;
- AA is divisible by BB.
Print AA and BB which satisfy the given conditions. If no such pair of AA and BB exists, print −1−1 instead.
codechef code
int main() {
int t;
cin >> t;
while(t--) {
int x, y, z;
cin >> x >> y >> z;
if((y * x) % z == 0) {
cout << y * x << " " << z << "\n";
}
else if((z * y) % x == 0) {
cout << z * y << " " << x << "\n";
}
else if((z * x) % y == 0) {
cout << z * x << " " << y << "\n";
}
else {
cout << -1 << "\n";
}
}
return 0;
}
my code
int main() {
int t;
cin >> t;
while(t--) {
int x, y, z;
cin >> x >> y >> z;
if((y * x) % z == 0) {
cout << y * x << " " << z << "\n";
}
else if((z * x) % y == 0) {
cout << z * x << " " << y << "\n";
}
else if((z * y) % x == 0) {
cout << z * y << " " << x << "\n";
}
else {
cout << -1 << "\n";
}
}
return 0;
}
result
Wrong Answer: Failed on a hidden test case