提交时间:2024-08-20 13:36:34

运行 ID: 168750

#include <bits/stdc++.h> using namespace std; int change(char *x,int b){ int num = 0; for(int i = 0;i < strlen(x);i++){ if(x[i] - 48 >= b) return -1; num *= b + x[i] - 48; } 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 = change(p,i); int qi = change(q,i); int ri = change(r,i); if(pi == -1 || qi == -1 || ri == -1) continue; if(pi * qi == ri){ B = i; break; } } if(B != 0) cout << B; else cout << '0'; return 0; }