In addition to the interesting game problem, I can't think of anything to describe. In addition to the useful knowledge, I can also lie to the ignorant children ............)
This is also a classic saying. It is called the bash game in English. Well, it was probably another thought of by bash.
The so-called bash game is:There are only a bunch of N items, and the two take items in turn. Each time at least one item is taken, up to m items are taken. Finally, Whoever obtains the light item is the winner.
Assume that n = m + 1. It is obvious that no matter how many items the current player takes, it cannot deny the fate of the player to be defeated. Our goal is always to lead to defeat,
Assuming m + 1 <n <2 (m + 1), the current player only needs to obtain (N-(m + 1) from it, resulting in a point of defeat (m + 1 ); assuming 2 (m + 1) <n <3 (m + 1), the current player only needs to retrieve
(N-2 (m + 1) items, the remaining 2 (m + 1) items in the heap, no matter how many items the opponent next to (1 <= x <= m ), number of items remaining S, m + 1 <S <2 (m + 1), we can take the corresponding number
The quantity of items leaves m + 1 items in the heap, SO 2 (m + 1) is also a must-have point; so the number of items in the heap S = K (m + 1) (k = 1, 2, 3 ......) It is a point of failure.
Finally, it is concluded that in this game:
1. If M> = N, the first player will win
2. If n = K (m + 1) + x (k = 1, 2, 3 ......; X <= m), wins first
3. If n = K (m + 1), the latter wins
Then .............................. You know
# include
using namespace STD; int main () {int cCase; CIN> cCase; while (cCase --) {int n, m; bool flag = true; CIN> N> m; If (M> = N) Flag = true; else if (N % (m + 1) Flag = true; elseflag = false; If (FLAG) cout <"first"