December Circuits '18 || Hakerearth || Picking coins
Picking coins
Alice and Bob are playing a game of picking coins. They are given a large pile of coins and an integer . In the move of any player, coins are picked from the pile. A player who is not able to make the move during his turn loses. You are required to predict the winner of the game.
Note: In every turn, Alice plays first followed by Bob.
Input format
For each test case, you are required to print the name of the winner of the game. You have to print either Alice or Bob depending upon who is the winner of the game.
Constraints
Note: In every turn, Alice plays first followed by Bob.
Input format
- First line: that represents the total number of test cases
- Each line of the test case: Two space-separated integers and
For each test case, you are required to print the name of the winner of the game. You have to print either Alice or Bob depending upon who is the winner of the game.
Constraints
Explanation
Test Case 1
In the first move: Alice first removes 3 coins, then Bob also removes 3 coins.
In the second move: Alice has to remove 9 coins but since only 4 are available, Alice loses and Bob wins.
Test Case 2
In the first move: Alice first removes 2 coins, then Bob also removes 2 coins
In the second move: Alice removes 4 coins, then Bob also removes 4 coins and only 2 coins remain.
In the third move: Alice has to remove 8 coins but it is not possible so Bob wins.
Similarly, the other two test cases can be followed.
In the first move: Alice first removes 3 coins, then Bob also removes 3 coins.
In the second move: Alice has to remove 9 coins but since only 4 are available, Alice loses and Bob wins.
Test Case 2
In the first move: Alice first removes 2 coins, then Bob also removes 2 coins
In the second move: Alice removes 4 coins, then Bob also removes 4 coins and only 2 coins remain.
In the third move: Alice has to remove 8 coins but it is not possible so Bob wins.
Similarly, the other two test cases can be followed.
Time Limit:1.0 sec(s) for each input file.
Memory Limit:256 MB
Source Limit:1024 KB
Marking Scheme:Marks are awarded if any test case passes.
Allowed Languages:Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic
My solution:
#include<stdio.h>
#include<math.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long int n,k,po;
scanf("%ld%ld",&n,&k);
for(int i=1;;i++)
{
po=pow(k,i);
if((n-po)<0){
printf("\nBob");
break;
}
else
n-=po;
if((n-po)<0){
printf("\nAlice");
break;
}
else
n-=po;
}
}
}
Comments
Post a Comment