#P8870. Mixed Radix Addition
Mixed Radix Addition
Mixed Radix Addition
You are given two numbers a and b represented in a special mixed radix numeral system. In this numeral system, the digits are given from low to high (from right to left), and the base of the ith digit (starting from i = 1) is i+1. That is, the least significant digit is in base $2$, the next digit is in base $3$, the next in base $4$, and so on.
Your task is to compute the sum of the two numbers and output the result in the same numeral system.
Explanation: When adding two digits at position i (with i = 1 being the units place), you should add the digits along with any carry from the previous position. Then, the digit for that position is the remainder when divided by i+1 and carry over the quotient to the next higher position. Continue until all digits and any remaining carry are processed.
The following formula explains the addition at the ith position:
$$\text{{digit}}_i = (a_i + b_i + \text{{carry}}) \mod (i+1) $$$$\text{{carry}} = \left\lfloor \frac{a_i + b_i + \text{{carry}}}{i+1} \right\rfloor $$Note: If one number has fewer digits than the other, assume the missing digits to be 0.
inputFormat
The input consists of two lines. The first line contains the number a and the second line contains the number b in the mixed radix system.
Each number is given as a string of digits. The most significant digit appears first. It is guaranteed that each digit is valid for its corresponding position: for the ith digit from the right (starting at i = 1), the digit is in the range \(0\) to \(i\) (inclusive).
outputFormat
Output a single line, the sum of the two numbers in the same mixed radix system. The result should not have any leading zeros unless the result is zero.
sample
1
1
10