GAME OF COUNTERS
All submissions for this problem are available.
Cisco and Harry play a game. They have a counter set to N.In every game, Cisco gets the first turn and the turns alternate thereafter. In the game, they perform the following operations.
- If N is not a power of 2, reduce the counter by the largest power of 2 less than N.
- If N is a power of 2, reduce the counter by half of N.
- The resultant value is the new N, which is again used for subsequent operations.
- The first line contains an integer T, the number of testcases.
- T lines follow. Each line contains N, the initial number set in the counter.
- For each test case, print the winner's name in a new line. So if Cisco wins the game, print Cisco. Otherwise, print Harry.
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 264 - 1
The game ends when the counter reduces to 1, i.e., N == 1, and the last person to make a valid move wins.
Given N, your task is to find the winner of the game.
Note, if the counter is already set to 1, then Harry wins, because it's Cisco's turn and he can't make a move.
Input: 1 6 Output: Harry
- As 6 is not a power of 2, Cisco reduces the largest power of 2 less than 6 i.e., 4, and hence the counter reduces to 2.
- As 2 is a power of 2, Harry reduces the counter by half of 2 i.e., 1. Hence the counter reduces to 1
As we reach the terminating condition with N == 1, Harry wins the game.
|Time Limit:||10 sec|
|Source Limit:||1000000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, 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, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions