#T363. Blah数集
Blah数集
Description
The great mathematician Gauss discovered an interesting set of natural numbers called Blah during his childhood. For a base a, the set Ba is defined as follows:
ais the base of the setBaand is the first element ofBa.- If
xis in the setBa, then2x + 1and3x + 1are also inBa. - No other elements are in
Ba.
Now, little Gauss wants to know: if the elements of Ba are arranged in ascending order, what is the value of the N-th element?
Input Format
The input consists of multiple lines. Each line contains two numbers: the base a (1 ≤ a ≤ 50) of the set and the desired element index n (1 ≤ n ≤ 1,000,000).
Output Format
For each input, output the value of the n-th element in the set Ba.
1 100
28 5437
418
900585