6870.Grundy's Game

Time Limit: 1s Memory Limit: 512MB

There is a heap of $n$ coins and two players who move alternately. On each move, a player chooses a heap and divides into two nonempty heaps that have a different number of coins. The player who makes the last move wins the game.

Your task is to find out who wins if both players play optimally.

Input Format(From the terminal/stdin)

The first input line contains an integer $t$ : the number of tests.

After this, there are $t$ lines that describe the tests. Each line has an integer $n$ : the number of coins in the initial heap.

  • $1 \le t \le 10^5$
  • $1 \le n \le 10^6$

Output Format(To the terminal/stdout)

For each test case, print "first" if the first player wins the game and "second" if the second player wins the game.

Sample Input

Copy
3
6
7
8
 \n
 \n
 \n
 \n

Sample Output

Copy
first
second
first
     \n
      \n
     \n
Source: CSES, Mathematics, 2207

Submit

请先 登录

© 2025 FAQs