QOJ.ac

QOJ

حد الوقت: 4 s حد الذاكرة: 256 MB مجموع النقاط: 100 قابلة للهجوم ✓

#12858. 考拉兹猜想

الإحصائيات

Collatz 函数 $f$ 定义在正整数上,如下所示:

$$ f(x) = \begin{cases} \frac{x}{2}, & \text{若 } x \pmod 2 = 0, \\ 3 \cdot x + 1, & \text{其他情况。} \end{cases} $$

我们定义一个数 $x$ 的 Collatz 序列为 $x, f(x), f(f(x)), \dots$。例如,对于 10,序列为 $10, 5, 16, 8, 4, 2, 1, 4, 2, 1, \dots$。Collatz 猜想指出,对于任何正整数,其 Collatz 序列最终都会到达 “4, 2, 1” 循环。

这个问题尚未解决,因此我们不会要求你证明或反驳该猜想。只需找到一个随机数的 Collatz 序列中第一次出现 1 的位置。你可以在下方的“说明”部分找到本题中“随机”一词的确切含义。

输入格式

输入的第一行也是唯一一行包含一个二进制表示的整数 $n$ ($1 \le n \le 2^{200\,000}$)。输入不包含前导零。

输出格式

输出一个整数:$n$ 的 Collatz 序列中第一次出现 1 的位置。序列元素从 0 开始编号。尽管输入是随机的,但保证每个测试点的答案都是有限的。

样例

样例输入 1

1010

样例输出 1

6

说明

测试分为三类:

  1. 样例;
  2. “小型”测试:$n \le 2^{1000}$,$n$ 是随机的,种子由评测组手动选择;
  3. “大型”测试:无额外限制,$n$ 是随机的,种子是随机选择的,且未研究生成测试数据的结构。

此处,“$n$ 是随机的”意味着“$n$ 的长度是手动选择的,第一位数字为 1,所有其他数字使用某种伪随机数生成器均匀且独立地设置为 0 或 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.