Universal Cup Judging System

Universal Cup

حد الوقت: 12.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓
الإحصائيات

你是一名充满朝气的本科生,在观看了关于 Collatz 猜想的 YouTube 视频后,对如何解决它产生了一些绝妙的想法!你现在可以想象——为了你的本科毕业论文,你将解决 Collatz 猜想,并像 von Neumann、Terence Tao 和 Ramanujan 那样成为教科书上的天才。你的论文导师认为这是一个糟糕的主意;他们警告你,在你之前已经有许多人尝试过这条路并以失败告终。但他们就是不明白——那是他们,而你是你。这不一样。你是特别的。

由于你的坚持,你的论文导师勉强同意支持你,但条件是你必须通过解决这个包含比 Collatz 猜想中更困难、更广义设置的问题来证明自己!

给定一个由不同整数组成的集合 $M$ 和一个整数 $n$。你的目标是仅使用以下两种操作将 $n$ 转换为 $1$:

  1. 选择一个 $m \in M$,并将 $n$ 替换为 $mn + 1$。
  2. 选择 $n$ 的一个质因数 $p$,并将 $n$ 替换为 $n/p$。

将 $n$ 转换为 $1$ 所需的最少操作次数是多少?如果无法将 $n$ 转换为 $1$,也请说明。

输入格式

输入的第一行包含一个整数 $t$,表示测试用例的数量。接下来是 $t$ 个测试用例的描述。

每个测试用例包含一行,包含 $2 + |M|$ 个空格分隔的整数,其中 $|M|$ 表示 $M$ 的大小。前两个整数是 $n$ 和 $|M|$,其余 $|M|$ 个整数是 $M$ 中的元素。

  • $1 \le t \le 262144$
  • $2 \le n \le 2097152$
  • $1 \le |M| \le 8$
  • 对于 $M$ 中的每个 $m$,都有 $1 \le m \le 64$
  • 每个文件中没有两个完全相同的测试用例。
  • $M$ 中的元素按递增顺序给出。

输出格式

对于每个测试用例,输出一行,内容为以下两者之一:

  • 一个整数,表示将 $n$ 转换为 $1$ 所需的最少操作次数,或者
  • 字符串 FIELDS MEDAL,表示无法将 $n$ 转换为 $1$。

重要说明:输出对大小写敏感,因此你需要全部使用大写字母输出。此外,输出中不要包含前导或尾随空格、两个连续的空格或制表符。

样例

输入 1

2
84 2 3 6
18588 3 18 25 44

输出 1

3
4

说明

  • 在第一个测试用例中,一种可能的操作序列为:$84 \to 12 \to 37 \to 1$。
  • 在第二个测试用例中,一种可能的操作序列为:$18588 \to 12 \to 301 \to 5419 \to 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.