QOJ.ac

QOJ

时间限制: 1 s 内存限制: 2048 MB 总分: 100 难度: [显示]

#14602. 黑板游戏

统计

为了帮助她的低年级学生理解质因数分解的概念,Aisha 发明了一个让他们在黑板上玩的游戏。游戏规则如下。

游戏由两名玩家轮流进行。最初,黑板上写有从 $1$ 到 $n$ 的整数。开始时,先手玩家可以选择任意一个偶数并将其圈起来。在接下来的每一步中,当前玩家必须选择一个数字,该数字要么是当前被圈起来的数字乘以某个质数,要么是当前被圈起来的数字除以某个质数。然后,该玩家擦除之前圈起来的数字,并圈出新选择的数字。当玩家无法进行操作时,该玩家输掉游戏。

为了帮助 Aisha 的学生,请编写一个程序,在给定整数 $n$ 的情况下,确定是先手(first)更有利还是后手(second)更有利,如果先手更有利,请找出一步获胜的先手开局操作。

输入格式

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

每个测试用例由单行组成,包含一个整数 $n$ ($2 \le n \le 10^7$),表示黑板上写着的最大数字。

在所有测试用例中,$n$ 的总和最多为 $10^7$。

输出格式

对于每个测试用例,如果先手玩家对于给定的 $n$ 具有必胜策略,则输出单词 first,后跟一个偶数——即任何可以延伸为必胜策略的合法第一步操作。如果后手玩家具有必胜策略,则仅输出单词 second

样例

输入样例 1

1
5

输出样例 1

second

说明 1

对于 $n = 5$,无论第一步如何选择,先手玩家都会输掉游戏。

  • 如果先手玩家从 $2$ 开始,后手玩家圈出 $4$,此时没有更多合法的操作。
  • 如果第一步是 $4$,后手玩家圈出 $2$。先手玩家随后必须圈出 $1$,后手玩家可以选择剩下的两个数字($3$ 或 $5$)之一即可获胜。

输入样例 2

2
12
17

输出样例 2

first 8
first 6

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.