#Lutece0553. Awkward Digits
Awkward Digits
Migrated from Lutece 553 Awkward Digits
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Bessie the cow is just learning how to convert numbers between different bases, but she keeps making errors since she cannot easily hold a pen between her two front hooves.
Whenever Bessie converts a number to a new base and writes down the result, she always writes one of the digits wrong. For example, if she converts the number into binary (i.e., base ), the correct result should be 1110
, but she might instead write down 0110
or 1111
. Bessie never accidentally adds or deletes digits, so she might write down a number with a leading digit of 0
if this is the digit she gets wrong.
Given Bessie's output when converting a number into base and base , please determine the correct original value of (in base ). You can assume is at most billion, and that there is a unique solution for .
Please feel welcome to consult any on-line reference you wish regarding base- and base- numbers, if these concepts are new to you.
Input
- Line : The base- representation of , with one digit written incorrectly.
- Line : The base- representation of , with one digit written incorrectly.
Output
- Line : The correct value of .
Samples
1010
212
14
Resources
USACO Nov 2011