eolymp
bolt
Try our new interface for solving problems
Problems

What Base Is This?

What Base Is This?

In positional notation we know the position of a digit indicates the weight of that digit toward the value of a number. For example, in the base \textbf{10} number \textbf{362} we know that \textbf{2} has the weight \textbf{10^0}, \textbf{6} has the weight \textbf{10^1}, and \textbf{3} has the weight \textbf{10^2}, yielding the value \textbf{3·10^2}+\textbf{6·10^1}+\textbf{2·10^0}, or just \textbf{300}+\textbf{60}+\textbf{2}. The same mechanism is used for numbers expressed in other bases. While most people assume the numbers they encounter everyday are expressed using base \textbf{10}, we know that other bases are possible. In particular, the number \textbf{362} in base \textbf{9} or base \textbf{14} represents a totally different value than \textbf{362} in base \textbf{10}. For this problem your program will presented with a sequence of pairs of integers. Let's call the members of a pair \textbf{X} and \textbf{Y}. What your program is to do is determine the smallest base for \textbf{X} and the smallest base for \textbf{Y} (likely different from that for \textbf{X}) so that \textbf{X} and \textbf{Y} represent the same value. Consider, for example, the integers \textbf{12} and \textbf{5}. Certainly these are not equal if base \textbf{10} is used for each. But suppose \textbf{12} was a base \textbf{3} number and \textbf{5} was a base \textbf{6} number? \textbf{12} base \textbf{3} = \textbf{1·3^2}+\textbf{2·3^0}, or \textbf{5} base \textbf{10}, and certainly \textbf{5} in any base is equal to \textbf{5} base \textbf{10}. So \textbf{12} and \textbf{5} can be equal, if you select the right bases for each of them! \InputFile On each line of the input data there will be a pair of integers, \textbf{X} and \textbf{Y}, separated by one or more blanks; leading and trailing blanks may also appear on each line, are are to be ignored. The bases associated with \textbf{X} and \textbf{Y} will be between \textbf{1} and \textbf{36} (inclusive), and as noted above, need not be the same for X and Y. In representing these numbers the digits \textbf{0} through \textbf{9} have their usual decimal interpretations. The uppercase alphabetic characters \textbf{A} through \textbf{Z} represent digits with values \textbf{10} through \textbf{35}, respectively. \OutputFile For each pair of integers in the input display a message similar to those shown in the examples shown below. Of course if the two integers cannot be equal regardless of the assumed base for each, then print an appropriate message; a suitable illustration is given in the examples.
Time limit 1 second
Memory limit 64 MiB
Input example #1
12 5
10 A
12 34
123 456
1 2
10 2
Output example #1
12 (base 3) = 5 (base 6)
10 (base 10) = A (base 11)
12 (base 17) = 34 (base 5)
123 is not equal to 456 in any base 2..36
1 is not equal to 2 in any base 2..36
10 (base 2) = 2 (base 3)