QOJ.ac

QOJ

حد الوقت: 3 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#511. 差值

الإحصائيات

“最小不同序列”(Smallest Different Sequence,简称 SDS)是一个由正整数构成的序列,其构造方式如下:$A_1 = r \ge 1$。对于 $n > 1$,有 $A_n = A_{n-1} + d$,其中 $d$ 是尚未在序列中出现过,且也未在序列中任意两个已有数值之差中出现过的最小正整数。例如,若 $A_1 = 1$,由于 $2$ 是目前序列中尚未出现的最小数字,因此 $A_2 = A_1 + 2 = 3$。同理,$A_3 = 7$,因为 $1, 2, 3$ 已经通过序列中的数值或序列中两个数值之差被涵盖了。继续下去,我们已经涵盖了 $1, 2, 3, 4, 6, 7$,剩下的最小差值为 $5$;因此 $A_4 = 12$。该 SDS 的后续数值依次为 $20, 30, 44, 59, 75, 96, \dots$。对于一个正整数 $m$,你需要确定 $m$ 在该 SDS 中首次出现的位置,即 $m$ 首次作为 SDS 中的一个数值,或者首次作为 SDS 中两个数值之差出现的位置。在上述 SDS 中,$12, 5, 9$ 和 $11$ 均在第 $4$ 步首次出现。

输入包含一行,由两个正整数 $A_1$ 和 $m$ 组成($1 \le r \le 100$,$1 \le m \le 200\,000\,000$)。

输出最小的 $n$,使得序列 $A_1, \dots, A_n$ 中包含 $m$(作为序列中的数值或序列中两个数值之差)。所有答案均满足 $n \le 10\,000$。

样例

输入格式 1

1 5

输出格式 1

4

输入格式 2

1 12

输出格式 2

4

输入格式 3

5 1

输出格式 3

2

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.