#t442. Blah数集

Blah数集

The Blah Set

Problem Description

The great mathematician Gauss, as a child, happened upon an interesting set of natural numbers called BlahBlah. For a base aa, the set BlahBlah is defined as follows:

(1) aa is the base of BlahBlah and its first element;

(2) if xx is in BlahBlah, then 2x+12x+1 and 3x+13x+1 are also in BlahBlah;

(3) there are no other elements.

Little Gauss wants to know: if the elements of BlahBlah are sorted in increasing order, what is the nn-th element?

Input Format

Two numbers: the base aa of the set (1≤a≤501 \le a \le 50) and the index nn of the requested element (1≤n≤1061 \le n \le 10^6).

Output Format

The value of the nn-th element of BlahBlah.

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.