#P17188. [ICPC 2017 Hong Kong R] Sets

    ID: 16770 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>数学高精度2017ICPC香港

[ICPC 2017 Hong Kong R] Sets

题目描述

For a fixed number nn, we define S1S_1 as the set of integers 1,2,…,n1, 2, \dots, n. And for any i>1i > 1, we define SiS_i as a set containing all sums of two different numbers in Si−1S_{i-1}.

For example, if n=3n = 3, we have

$$\begin{matrix} S_1 & = &\{1,2,3\},\\ S_2 & = &\{3,4,5\},\\ S_3 & = &\{7,8,9\},\\ S_4 & = &\{15, 16, 17\}.\\ \end{matrix}$$

Then, we sort each set respectively, and combine them in order into a sequence LL. In the above case, we have the sequence L=1,2,3,3,4,5,7,8,9,15,16,17,…L = 1, 2, 3, 3, 4, 5, 7, 8, 9, 15, 16, 17, \dots.

Now, given integers nn and kk, what is the kk-th number in sequence LL?

输入格式

The input file contains several test cases, please handle it to the end of file.

For each case, there is only one line containing two integers nn and kk (n≤1000,k≤101000n \le 1000, k \le 10^{1000}). When n=3n = 3, the input satisfies that k≤100000k \leq 100000.

输出格式

For each case, output one integer indicating the kk-th number of the sequence. Output −1-1 if it does not exist.

4 6
2 20
4
-1