-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path1331.cc
52 lines (46 loc) · 989 Bytes
/
1331.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//Name: Multiply
//Level: 1
//Category: 数学,やるだけ
//Note:
/*
* 進数変換するだけ.
* p,q,rの範囲上,long longでないとオーバーフローのおそれがあることに注意.
*/
#include <iostream>
#include <algorithm>
using namespace std;
int max_digit(int n) {
int ans = 0;
while(n) {
ans = max(ans, n%10);
n /= 10;
}
return ans;
}
long long convert(int n, int base) {
long long res = 0;
long long b = 1;
while(n) {
res += (n%10) * b;
n /= 10;
b *= base;
}
return res;
}
int main() {
int T;
cin >> T;
while(T--) {
int p,q,r;
cin >> p >> q >> r;
int ans = 0;
for(int b = max(max_digit(p), max(max_digit(q), max_digit(r)))+1; b <= 16; ++b) {
if(convert(p, b) * convert(q, b) == convert(r, b)) {
ans = b;
break;
}
}
cout << ans << endl;
}
return 0;
}