Run ID:110178

提交时间:2025-02-15 13:16:52

#include <iostream> using namespace std; int main() { int c; cin >> c; // 读取测试样例的个数 while (c--) { int a, b, c; cin >> a >> b >> c; // 读取 a, b, c 的值 // 检查是否有解 if (a == 1 || b == 1 || c == 1) { cout << "Impossible" << endl; continue; } // 检查 a, b, c 之间是否存在公因数 if (gcd(a, b) > 1 || gcd(b, c) > 1 || gcd(a, c) > 1) { cout << "Impossible" << endl; continue; } // 使用中国剩余定理求解 int x = 0; for (int k = 0; k < a; k++) { int candidate = k * b * c; if (candidate % a == 0 && (candidate + 1) % b == 0 && (candidate + 2) % c == 0) { x = candidate; break; } } if (x == 0) { cout << "Impossible" << endl; } else { cout << x << endl; } } return 0; }