Wednesday, September 1, 2010

What is the base of a number

Problem Description

We use letters (A-Z) and digits (0-9) to represent a number. For example A0 in hexadecimal number is equal to 160 in decimal number and 240 in octal number. Given 2 numbers which are equal in two different base and given base of one number you have to find out base of another number.

Input

Three words in each line separated by spaces: first word is first number and second word is base of first number in decimal and third word is a number that is equal to first number for some different base. Letters will be capital always.

Output


Print out the base of second number in decimal and zero if can not find any base that is 2-36.

Sample input

A0 16 160
160 10 240

Sample Output

10
8

1 comment:

  1. vai, eida ektu painful lagtese. mone hoy bit shifting dia try dite hoibo. Kintu bit shifting vuilla gesi. azke rate porum...

    ReplyDelete