A simple stone game
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 174 accepted submission (s): 79
Problem descriptionafter he has learned how to play Nim game, Mike begins to try another stone game which seems much easier.
The game goes like this: two players start the game with a pile of N stones. they take stones from the pile in turn and every time they take at least one stone. the one who goes first can take at most n-1 stones for his first move. from then on a player can
Take at most K times as your stones as his opponent has taken last time. for example, if one player takes m stones in his turn, then the other player can take at most k × m stones next time. the player who takes the last stone wins the game. suppose that those
Two players always take the best moves and never make mistakes, your job is to find out who will definitely win the game.
Inputthe first line contains a integer T, indicating that there are t test cases following. (T <= 20 ).
Each test case is a line consisting of two integer N and K. (2 <= n <= 10 ^ 8, 1 <= k <= 10 ^ 5 ).
Outputfor each test case, output one line starting with "Case N:", n is the case number. and then, if the first player can ensure a winning, print the minimum number of stones he shoshould take in his first turn. otherwise, print "lose ". please note that there is
Blank following the colon.
Sample Input
516 111 132 234 219 3
Sample output
Case 1: loseCase 2: 1Case 3: 3Case 4: loseCase 5: 4