QOJ.ac

QOJ

時間限制: 8 s 記憶體限制: 1024 MB 總分: 27

#5791. 多进制快乐数

统计

给定一个整数 $N$,将其替换为它各位数字的平方和。如果重复此过程最终得到数字 1,则称该数为快乐数。例如,如果从 82 开始:

8*8 + 2*2       = 64 + 4    = 68,  重复:
6*6 + 8*8       = 36 + 64   = 100, 重复:
1*1 + 0*0 + 0*0 = 1 + 0 + 0 = 1 (快乐! :)

由于该过程最终结果为 1,因此 82 是一个快乐数。

注意,一个数在某些进制下可能是快乐数,但在其他进制下则不是。例如,十进制数 82 在三进制下(表示为 10001)就不是快乐数。

你是世界上顶尖的数字侦探之一。一些进制数联合起来(是的,它们是有组织的!)雇佣你完成一项重要任务:找出大于 1 且在所有给定进制下均为快乐数的最小整数。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例占一行,包含一个由空格分隔的互不相同的整数列表,代表给定的进制。进制列表始终按升序排列。

输出格式

对于每个测试用例,输出:

Case #X: K
其中 $X$ 是测试用例编号(从 1 开始),$K$ 是在所有给定进制下均为快乐数的最小整数(大于 1)的十进制表示。

样例

输入格式 1

3
2 3
2 3 7
9 10

输出格式 1

Case #1: 3
Case #2: 143
Case #3: 91

说明

请记住,你必须提交用于解决该问题的所有代码。

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.