Module: Number systems


Problem

4/9

Base Equation

Problem

The notation AX means that A is a notation of a number in the base number system X. If \(X>10\), then to write a number other than numbers from 0 to 9  uppercase English letters from A to Z. Under this condition, X cannot be greater than 36.
 
It is necessary to find the solution of the equation \(A_X = B\) given A and B, or report that he has no solutions.
 
Input
The first line contains the number A (a non-empty sequence of numbers from 0 to 9 and uppercase English letters from A > to Z without leading zeros), in the second -  number B (\(1 <= B <= 10^7\)).
 
Output
Print either the smallest base that satisfies the equation, or 0 if the equation has no solutions.

Add the missing piece of code to the program.

 

Examples
# Input Output
1 A1
161
16
2 201
26
0