QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100

#3812. 谢尔顿数

Estadísticas

根据 Sheldon Cooper 的说法,最好的数字是 73。用他自己的话说: “最好的数字是 73。73 是第 21 个素数。它的镜像 37 是第 12 个素数,而 37 的镜像 21 是 7 和 3 的乘积。在二进制中,73 是一个回文数:1001001,反过来也是 1001001。完全一样。”

素数很无聊,回文数也一样。另一方面,73 的二进制表示非常引人注目:它是一个 1,后面跟着 2 个 0,再跟着 1 个 1,再跟着 2 个 0,最后跟着 1 个 1。这是一个有趣的模式,我们可以将其推广:$N$ 个 1,后面跟着 $M$ 个 0,再跟着 $N$ 个 1,再跟着 $M$ 个 0,以此类推,以 $N$ 个 1 或 $M$ 个 0 结尾。对于 73,$N=1$,$M=2$,共有 5 段相等的符号。若 $N=2$,$M=1$ 且有 4 段,我们将得到字符串 110110,这是 54 的二进制表示。

基于 Sheldon 的深刻见解,我们引入“Sheldon 数”的概念:一个正整数,其二进制表示符合模式 $ABABAB \dots ABA$ 或模式 $ABABAB \dots AB$,其中所有 $A$ 的出现代表一个包含 $N$ 个 1 的字符串,所有 $B$ 的出现代表一个包含 $M$ 个 0 的字符串,且 $N > 0$,$M > 0$。此外,在该表示中,必须至少出现一次字符串 $A$(但字符串 $B$ 出现的次数可以为零)。

许多重要的数字都是 Sheldon 数:1755(里斯本大地震发生的年份)、1984(奥威尔名著中的年份)以及 2015(当前年份)!此外,Sheldon 提到的 21 也是一个 Sheldon 数,42 也是,它是超级计算机“深思”对生命、宇宙以及一切的终极问题的答案。

显然,Sheldon 数有无穷多个,但它们比素数更稠密还是更稀疏呢?

任务

你的任务是编写一个程序,给定两个正整数,计算在给定范围内的 Sheldon 数的个数。

输入格式

输入包含一行,由两个空格分隔的整数 $X$ 和 $Y$。

数据范围

$0 \le X \le Y < 2^{63}$

输出格式

输出包含一行,一个数字,表示大于或等于 $X$ 且小于或等于 $Y$ 的 Sheldon 数的个数。

样例

输入格式 1

1 10

输出格式 1

10

说明

1 到 10 之间的所有数字都是 Sheldon 数。

输入格式 2

70 75

输出格式 2

1

说明

73 是该范围内唯一的 Sheldon 数。

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.