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 N coins and an integer k. In the ith move of any player, ki 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
  • First line: T that represents the total number of test cases
  • Each line of the test case: Two space-separated integers N and k  
Output 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
1T100
1N,k1018             

SAMPLE INPUT
 
4
10 3
14 2
18 10
37 5
SAMPLE OUTPUT
 
Bob
Bob
Alice
Alice
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.
 
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

Popular posts from this blog

code vita 2018 questiones

Detoll and Mom kit for free