63 845
Assignments Done
99,2%
Successfully Done
In August 2018

Answer to Question #53719 in C++ for Hema

Question #53719
Alice and Bob are playing a game called "Stone Game". Stone game is a two-player game. Let N be the total number of stones. In each turn, a player can remove 1, 2 or 3 stones. The player who picks the last stone, loses. They follow the "Ladies First" norm. Hence Alice is always the one to make the first move. Your task is to find out whether Alice can win, if both play the game optimally.
Input Format:

First line starts with T, which is the number of test cases. Each test case will contain N number of stones.

Output Format:

Print "Yes" in the case Alice can win, else prints "No".

Constraints:
1<=T<=10

1<=N<=10000


Sample Input and Output

SNo. Input Output
1
2
1
3


No
Yes
Expert's answer
Answer
Start By Considering the base cases:
• First for n=1, Obviously Alice Loses.
• For n = 2,3,4 Alice Wins.
• For n = 5, Bob Wins.
Now for further 3 positions (i.e. 6,7,8), we can make Alice reach Bob's Winning position but start-ing from Bob ( i.e. (6-1), (7-2), (8-3) ). Then, Bob can only return Alice her winning positions.
• So, Alice Wins for n = 6,7,8.
Similarly for n= 9 Bob Wins. Continuing this reasoning, we can say that for n=1,5,9 i.e for any number of form 4n-3, Bob wins and for the rest, Alice wins.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions