#P11056. Fire and Big

Fire and Big

Problem Description

Little F wants to play a game with others, but he does not want to lose, so he asks you to help him study a strategy.

There are mm stones. Little F and Little B take turns removing stones. Little F goes first. The player who cannot make a move loses.

Given a positive integer nn, the number of stones removed each time kk (kk is a positive integer) must satisfy at least one of the following two conditions:

  • kk is a multiple of nn.
  • kk is a perfect square less than nn.

They will play TT games. In each game, nn is fixed, and only the number of stones mm changes.

For each game, assuming both players are smart enough, determine who has a winning strategy.

Input Format

The first line contains two positive integers T,nT, n.

The second line contains TT positive integers mm, where each mm is the number of stones in that game.

Output Format

Output a string of length TT, one character per game. Each character is F or B, meaning the first player wins or the second player wins in that game, respectively.

5 2
1 2 3 4 5
FFBFF

Hint

Sample Explanation

The following explains that when n=2,m=3n = 2, m = 3, the second player will win. Consider the number of stones the first player removes on the first move:

  • If the first player removes 11 stone, then the second player can remove all remaining 22 stones.
  • If the first player removes 22 stones, then the second player can remove the remaining 11 stone.

Therefore, no matter what, the second player will always win.

Constraints

Test Point ID nn mm\le
11 5×105\le 5\times 10^5 11
232\sim 3 5\le 5 55
464\sim 6 105\le 10^5 nn
787\sim 8 =2=2 10910^9
9119\sim 11 5\le 5
121412\sim 14 103\le 10^3
151715\sim 17 105\le 10^5
182018\sim 20 5×105\le 5\times 10^5

For all testdata, it is guaranteed that 1T,n5×1051\le T, n\le 5\times 10^5 and 1m1091\le m\le 10^9.

For odd-numbered test points, the memory limit is 512 MB512\ \text{MB}; for even-numbered test points, the memory limit is 64 MB64\ \text{MB}.

Translated by ChatGPT 5