Geek and his friend are playing a coin game. At the beginning there are N coins. Given two numbers X and Y. In each move a player can pick X, Y or 1 coins. Geek always starts the game. The player who picks the last coin wins the game. For a given value of N, find whether Geek will win the game or not if both are playing optimally.
Input : n = 5, x = 3, y = 4
Output : N
There are 5 coins, every player can pick 1 or 3 or 4 coins on his/her turn. Geek can win by picking 3 coins in first chance. Now 2 coins will be left so his frined will pick one coin and now Geek can win by picking the last coin.
First line of the input contains an integer T, denoting the number of test cases. Then T test case follows. The only line of the each test case contains three space separated integer denoting the values of N, X and Y, respectively.
For each test case output a single line containg either 'G' or 'N'. If Geek wins print 'G' else print 'N'.
2 3 4
10 2 3
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.