Abhi And Ambi play a game
All submissions for this problem are available.
Two friends Abhi and Ambi are playing a game. The game is played over N piles of coins with each pile having A coins. It is given that A is Prime. The game is played according to some rules.
1. Each player in his turn can choose a pile of coins and remove some X>0 number of coins from the chosen pile.
2. The number X chosen should be such that X number of coins were not removed in any of the previous moves from any of the piles . For example , if a player removes 3 coins from a certain pile in his turn , no player can remove 3 coins from any pile in any of the successive turns.
3. Abhi always goes first.The players play in alternating turns. It is given that both players play optimally. The player who can't move in his turn loses. For every test case , print “Abhi” if Abhi wins and “Ambi” otherwise.
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains N and A respectively as described above.
For every test case print the winner's name in a new line.
- 1 ≤ T ≤ 10^5
- 1 ≤ N ≤ 10^5
- 2 ≤ A ≤ 10^9 (A wiil be prime)
SubtasksSubtask #1 (20 points), Time limit : 1 sec
1 ≤ T ≤ 100000, 1 ≤ N ≤ 10^5 , 2 ≤ A ≤ N (A is prime)
Subtask #2 (80 points), Time limit : 1 sec
1 ≤ T ≤ 100000, 1 ≤ N ≤ 10^5, 2 ≤ A ≤ 10^9 (A is prime)
Input: 2 1 2 2 2 Output: Abhi Ambi
In the sample input 1, there is a single pile of 2 coins. Abhi removes both the coins from the pile in his move. Now 0 coins are left and hence Ambi can't remove any coins in his move. So Abhi wins the game.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions