A simple stone game

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.