I have recently encounter this game-theory problem:

"Two player X and Y is going to play a game. Initially, they choose a number *P* (*P* ≤ 10^{18}) and a set of number *A*_{1}, *A*_{2}, *A*_{3}, ..., *A*_{n} (*n* ≤ 5000, 0 ≤ *A*_{i} < *P*). They will take their turns alternatively. In each turn, one player will remove a number from the set. After K turns, if the sum of all remaining numbers in the set is divisible by P, player X will win. Otherwise, player Y will win.

Determine who will win the game, if both of them play optimally. (The name of player who make the first move will be given in the input)"

I completely have no efficient approach for this problem (except the naive bitmask DP). Can anyone give me an hint? Thanks in advance.