#P4973. X-Star Numeral System Conversion

    ID: 18212 Type: Default 1000ms 256MiB

X-Star Numeral System Conversion

X-Star Numeral System Conversion

You are given a numeral system defined by a base value X and a number represented as a string. The numeral system is defined as follows:

For a given number represented by string S with length n, each digit S[i] (with 0-based index from left) is first converted to an integer d by subtracting the ASCII code of '0'. Then, its contribution is computed as:

\(d \times X^{(n-1-i)}\)

The final value is obtained by multiplying the contribution of every digit. Since the result can be extremely large, you are not required to output the number itself, but rather the number of digits of the final product when represented in base 10.

Note: If any digit in the number is 0, then one of the factors is 0 and hence the product is 0 (considered as having 1 digit).

Example:
For X = 3 and S = "2363", the computation is as follows:

  • For '2': \(2 \times 3^3 = 2 \times 27 = 54\)
  • For '3': \(3 \times 3^2 = 3 \times 9 = 27\)
  • For '6': \(6 \times 3^1 = 6 \times 3 = 18\)
  • For '3': \(3 \times 3^0 = 3 \times 1 = 3\)

The product is \(54 \times 27 \times 18 \times 3 = 78732\), which has 5 digits. Thus, the output is 5.

inputFormat

The input consists of two tokens separated by spaces or newlines:

  • An integer X (the base of the numeral system).
  • A string S representing a non-negative number (each character is a digit between '0' and '9').

outputFormat

Output a single integer representing the number of digits in the product (when converted to a base 10 number) computed as the multiplication of each digit's contribution.

sample

3 2363
5