Interesting Numbers
Time limit2sMemory limit1024 MB
Find the n-th smallest positive integer whose base-k representation ends with an odd number of trailing zeros.
- Level
Medium7 of 10
- Topics
- Math, Combinatorics, Binary search, Number theory
- Solved
- No attempts yet
Statement
Roman collects numbers that seem interesting to him. For example, he currently considers a positive integer interesting if its representation in base ends with an odd number of zeros. For instance, when such numbers are and .
To add to his collection, Roman wants to find the -th smallest such number. Since he chose large enough, he cannot find it by hand.
Help Roman by writing a program that finds the number he needs to complete his collection.
Input
The first line of the input contains two integers and (, ).
Output
Output the -th smallest number whose representation in base ends with an odd number of zeros. Output this number in decimal.