#P2084. Base Conversion Expression
Base Conversion Expression
Base Conversion Expression
In this problem, you are given a base (M) and a number (N) represented in base (M). Your task is to output the decimal expansion expression of (N) in the form:
[ a_k \times M^k + a_{k-1} \times M^{k-1} + \cdots + a_0 \times M^0, ]
However, if a coefficient (a_i = 0), then that term should be omitted. For example, converting the binary number 10101 (i.e. ((10101)_2)) would yield:
[ 1 \times 2^4 + 1 \times 2^2 + 1 \times 2^0. ]
Note that terms with a coefficient of zero are not included in the expression.
inputFormat
The input consists of two lines. The first line contains an integer (M) denoting the base. The second line contains a string (N) which is the number in base (M). You can assume that (N) consists only of digits (0-9) and does not contain any leading zero unless the number is 0.
outputFormat
Output the expression in which each nonzero digit of (N) is represented as digit*M^exponent
. The terms should be joined with a plus sign '+' without extra spaces except the ones shown in the sample. If all digits are zero, output 0.
sample
2
10101
1*2^4+1*2^2+1*2^0