提交时间:2024-08-19 21:56:57

运行 ID: 168033

#include <iostream> #include <cstring> using namespace std; int ch(char* x, int b) { int num = 0; for (int i = 0; x[i]; i++) { if (x[i] - '0' >= b) return -1; num = num * b + x[i] - '0'; } return num; } int main() { char p[9], q[9], r[9]; cin >> p >> q >> r; int B = 0; for (int i = 2; i <= 16; i++) { int pi = ch(p, i); int qi = ch(q, i); int ri = ch(r, i); if (pi == -1 || qi == -1 || ri == -1) continue; if (pi * qi == ri) { B = i; break; } } cout << B << endl; return 0; }