[Click tips 23] Click here to get stones and click tips 23.

Source: Internet
Author: User

[Click tips 23] Click here to get stones and click tips 23.

Description
One day, TT was bored in the dormitory, and he played a stone game with his colleagues. However, due to limited conditions, he/they used wangzi's steamed buns As stones. The rules of the game are as follows. There is a pile of stones, the number is N (1 <= N <= 1000000), two people take several of them in turn, each time a maximum of M (1 <= M <= 1000000), the first to win the stone. We know that TT and his/her roommates are both very smart. If TT is used first, will he/she win the game?
Input
The first line is a positive integer n, indicating that n groups of test data exist.
The input contains less than 1000 groups of data. Each group contains one row of data. There are two numbers N and M, separated by spaces.
Output

Output a row for each group of data. If the first TT can Win the game, "Win" is output; otherwise, "Lose" is output (no quotation marks are required)


Analysis: this is the famous Bash Gaem)

There are only one pile of n items, and two people take things from the pile of items in turn, each time at least one, a maximum of m. The final winner wins.
If (m + 1) | n, the first hand is defeated; otherwise, the first hand is defeated.
Obviously, if n = m + 1, a maximum of m items can be taken at a time. Therefore, no matter how many items are taken by the first accessor, the latter can take the remaining items at a time, the latter wins. therefore, we send
Now we know how to win: If n = (m + 1) r + s, (r is an arbitrary natural number, s ≤ m), the first accessors should take s items, if the latter takes k (≤ m ),
Take m + 1-K, the result of the remaining (m + 1) (r-1), after maintaining such a method, then the first accessors certainly win. in a word, you must keep the multiples of (m + 1) to the opponent to win the game.

#include <stdio.h>#include <stdlib.h>int main(){int Cases;    int N,M;    scanf("%d",&Cases);    while(Cases--)    {scanf("%d %d",&N,&M);        if(N%(M+1)==0)printf("Lose\n");        elseprintf("Win\n");}return 0;}





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.