提交时间:2024-08-19 21:47:18

运行 ID: 168006

#include <iostream> using namespace std; int v(int num, int base) { int dec = 0; int p = 1; while (num > 0) { dec += (num % 10) * p; num /= 10; p *= base; } return dec; } int findB(int a, int b, int c) { for (int base = 2; base <= 16; base++) { int ad = v(a, base); int bd = v(b, base); int cd = v(c, base); if (ad * bd == cd) { return base; } } return 0; } int main() { int p, q, r; cin >> p >> q >> r; cout << findB(p, q, r) << endl; return 0; }