QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 256 MB 總分: 100

#11781. 集合

统计

对于一个固定的整数 $n$,我们定义 $S_1(n)$ 为整数集合 $\{1, 2, \dots, n\}$。对于任何 $i > 1$,我们定义 $S_i(n)$ 为包含 $S_{i-1}(n)$ 中任意两个不同数字之和的集合,即 $S_i(n) = \{x + y : x, y \in S_{i-1}(n), x \neq y\}$。

例如,当 $n = 3$ 时,我们有: $S_1(n) = \{1, 2, 3\}$ $S_2(n) = \{3, 4, 5\}$ $S_3(n) = \{7, 8, 9\}$ $S_4(n) = \{15, 16, 17\}$

然后,我们将每个集合分别排序,并按顺序将它们合并为一个序列 $L$。在上述情况下,我们得到的序列为 $L = 1, 2, 3, 3, 4, 5, 7, 8, 9, 15, 16, 17, \dots$。

现在,给定整数 $n$ 和 $k$,序列 $L$ 中的第 $k$ 个数是多少?

输入格式

输入文件包含多组测试数据,请处理到文件末尾。 对于每组测试数据,仅包含一行,包含两个整数 $n$ 和 $k$ ($n \le 1000, k \le 10^{1000}$)。

输出格式

对于每组测试数据,输出一个整数,表示序列中的第 $k$ 个数。如果该数不存在,则输出 $-1$。

样例

输入 1

4 6
2 20

输出 1

4
-1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.