#D. Little Rabbit's Equation

    传统题 1000ms 128MiB

Little Rabbit's Equation

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Description

Little Rabbit is interested in radix. In a positional numeral system, the radix is the number of unique digits, including the digit , used to represent numbers. For example, for the decimal system (the most common system in use today) the radix is ten, because it uses the ten digits from to . Generally, in a system with radix (), a string of digits denotes the number , where .

Little Rabbit casually writes down an equation. He wonders which radix this equation fits.

Input Format

The are several test cases. Each test case contains a string in a line, which represents the equation Little Rabbit writes down. The length of the string is at most . The input is terminated by the end of file.

The equation's format: A number, an operator, a number, the equals sign =, and a number. There's no blank space in the string.

Each number has at least digit, which may contain digital numbers to or uppercase letters to (which represent decimal to ). The number is guaranteed to be a non-negative integer, which means it doesn't contain the radix point or negative sign. But the number may contain leading zeros.

The operator refers to one of the basic elementary arithmetic operators, namely the plus sign +, the minus sign -, the multiplication sign *, or the division sign /. It is guaranteed that the number after the division sign will not be equal to . Please note that the division here is not integer division. For example, in the decimal system, 7/2=3 is not correct.

Output Format

For each test case, output an integer () in a line, which means the equation is correct in the system with radix . If there are multiple answers, output the minimum one. If there is no answer between and , output .
1+1=10
18-9=9
AA*AA=70E4
7/2=3
2
10
16
-1

2020HBCPC训练赛

未参加
状态
已结束
规则
ACM/ICPC
题目
8
开始于
2020-9-12 13:00
结束于
2020-9-12 17:00
持续时间
4 小时
主持人
参赛人数
15