881. Win or Lose

William and Jax are playing a game. The game is as follows :

You will be given an integer n. William goes first , In each move the player will choose any factor (excluding 1 and number itself) of the current number and replace it with chosen factor. The player who will not be able to make a move will win. Both players play the game optimally.

You have to tell which player will in the game. I William wins then output "William" else output "Jax".

Example 1:

Input : n = 6

Output : Jax

Explanation :

The factors for n = 6 are -> 2, 3. The William can choose any number and then Jax cannot make the move. So Jax wins.

Example 2:

Input : n = 30

Output : William

Explanation :

The factors for n = 30 are -> 2, 3, 5, 6, 10, 15. The William will choose number 6 optimally.

The factors of 6 are 2, 3. The Jax can choose any number and then William cannot make the move. So William wins.

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= n <= 109
0
class Solution{
public:
string winLose(int n){
//your code goes here
}
};
Test Case

Input:

N