PROBLEM LINK:Practice Setter: Hruday Pabbisetty DIFFICULTY:Simple PREREQUISITES:GameTheory and Basic Math would do. PROBLEM:Given an array $A$ containing $N$ elements, on which Bob and Alice are playing a game with Bob playing first, both of them having lucky numbers $a$ and $b$ respectively. In one move, a player can remove any number of elements from the array $A$ which are divisible by their lucky number. The player unable to remove any element loses the game. Find winner of the game if both players play optimally. SUPER QUICK EXPLANATION
EXPLANATIONFirst of all, let us classify the numbers present in the array into four categories.
Let Number of elements of the second type be the number of reserve moves of Bob and Number of numbers of the third type be Number of reserve moves of Alice. Since Bob is having the first move, it is ideal for Bob to remove all elements of the first type in the first move itself to force Alice to use reserve move in next move, if the array contains any number of the first type. This is because if after Bob's move, if there are any number of the first type present in the array, Alice can remove all of them, forcing Bob to use his reserve move in next move. Now, the player having lesser reserve move loses since that player shall run out of moves. In case both players had the same number of reserve moves, the player first to move shall lose (After removing numbers of the first type). It can be easily implemented by making two counter variables counting reserve moves of each player, and a flag determining whether there are any numbers of the first type in the array. Time ComplexityTime complexity is $O(N)$ per test case. AUTHOR'S AND TESTER'S SOLUTIONS:Setter's solution Feel free to Share your approach, If it differs. Suggestions are always welcomed. :)
This question is marked "community wiki".
asked 14 Jan, 15:58

This part of the editorial was very confusing: "In case both players had the same number of reserve moves, the player first to move shall lose (After removing numbers of the first type).". But thanks for the editorial. my solution answered 15 Jan, 02:14

can somebody help me. what is wrong in my solution https://www.codechef.com/viewsolution/22179724 answered 05 Feb, 12:30
