Log Chopping solution codeforces
There arelogs, the -th log has a length of meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.
errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into pieces. If the length of the chosen log is , and the lengths of the resulting pieces are and , then and have to be positive integers, and must hold. For example, you can chop a log of length into logs of lengths and , but not into logs of lengths and , and , or and .
The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?
Each test contains multiple test cases. The first line contains a single integer( ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer( ) — the number of logs.
The second line of each test case containsintegers ( ) — the lengths of the logs.
Note that there is no bound on the sum ofover all test cases.
For each test case, print “errorgorn” if errorgorn wins or “maomao90” if maomao90 wins. (Output without quotes).
2 4 2 4 2 1 1 1
In the first test case, errorgorn will be the winner. An optimal move is to chop the log of lengthinto logs of length . After this there will only be logs of length and log of length .
After this, the only move any player can do is to chop any log of lengthinto logs of length . After moves, it will be maomao90’s turn and he will not be able to make a move. Therefore errorgorn will be the winner.
In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.
I am the Founder and the creator of the blog neoideasblog.com where we share latest trivia questions and answers on a daily basis.