Friday, June 2, 2017

Add Numbers - Base N

Two numbers X and Y are provided with reference to base N. Add the numbers and print their sum with reference to base 10. 

Input Format: 

First line will contain the value of N. Second line will contain X and Y separated by one or more spaces. 

Output Format: 

First line will contain the sum of X and Y to the base 10. 

Example Input/Output 1: 

Input: 2 1010 11 
Output: 13 
Explanation: 1010 to the base 2 is 10. 11 to the base 2 is 3. Hence the sum is 10+3 = 13.

Solution:

b = int(input())
x = input().split()
print(int(x[0],b)+(int(x[1],b)))
Share: