#P14281. [ICPC 2025 WF] Blackboard Game【暂无 spj】
[ICPC 2025 WF] Blackboard Game【暂无 spj】
题目描述
To help her elementary school students understand the concept of prime factorization, Aisha has invented a game for them to play on the blackboard. The rules of the game are as follows.
The game is played by two players who alternate their moves. Initially, the integers from to are written on the blackboard. To start, the first player may choose any even number and circle it. On every subsequent move, the current player must choose a number that is either the circled number multiplied by some prime, or the circled number divided by some prime. That player then erases the circled number and circles the newly chosen number. When a player is unable to make a move, that player loses the game.
To help Aisha's students, write a program that, given the integer , decides whether it is better to move first or second, and if it is better to move first, figures out a winning first move.
输入格式
The first line of input contains an integer (), which is the number of test cases. The descriptions of test cases follow.
Each test case consists of a single line containing an integer (), which is the largest number written on the blackboard.
Over all test cases, the sum of is at most .
输出格式
For each test case, if the first player has a winning strategy for the given , output the word , followed by an even integer – any valid first move that can be extended to a winning strategy. If the second player has a winning strategy, output just the word .
1
5
second
2
12
17
first 8
first 6
提示
Explanation of Sample 1: For , the first player loses the game regardless of the first move.
- If the first player starts with , the second player circles , and there are no more valid moves left.
- If the first move is , the second player circles . The first player must then circle , and the second player may pick either of the remaining two numbers ( or ) to win.