#t442. Blah数集
Blah数集
The Blah Set
Problem Description
The great mathematician Gauss, as a child, happened upon an interesting set of natural numbers called . For a base , the set is defined as follows:
(1) is the base of and its first element;
(2) if is in , then and are also in ;
(3) there are no other elements.
Little Gauss wants to know: if the elements of are sorted in increasing order, what is the -th element?
Input Format
Two numbers: the base of the set () and the index of the requested element ().
Output Format
The value of the -th element of .
Sample Input 1
1 100
Sample Output 1
418
Sample Input 2
28 5437
Sample Output 2
900585
Limitation
1 s, 1024 KiB for each test case.