Welcome to ZOJ
Select Problem
ZOJ Problem Set - 2529
A+B in Hogwarts

Time Limit: 2 Seconds      Memory Limit: 65536 KB

If you are a fan of Harry Potter, you would know the school he is attending to, the Hogwarts School for Witchcraft and Wizardry. What you might not know is that Harry is never good at math, yet he doesn't want to bother Hermione for trivial A+B problems. Now your job is to write a simple calculator for him -- the calculator is so simple that it handles non-negative integer additions only.

What is not so simple is that the world of Witchcraft and Wizardry dosen't use a fixed radix numeration system. That is, an integer is represented with different radices for different digits -- the radix for the i-th digit is the i-th prime number. For example, the decimal number 2 is 10 in Hogwarts (let's denote it by 210 = 1,0H) since the radix for the 1st digit is the 1st prime number 2. Similarly we have 610 = 1,0,0H since the radix for the 2nd digit is 3.


The input consists of multiple test cases, each occupies a line with two integers in Hogwarts' system. Digits of a Hogwarts' integer are seperated by ',' and the two numbers are seperated by a space. Each number has at most 25 digits.


For each test case, print in one line the sum of the two given numbers in Hogwarts' system.

Sample Input
1,0 2,1
4,2,0 1,2,0
1 10,6,4,2,1
Sample Output

Author: CHEN, Yue
Source: CYJJ's Funny Contest #3, Having Fun in Summer
Submit    Status