21510_DoubleDealing

2022-5-16 18:19| 发布者: Hocassian| 查看: 39| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505356214899-Problem List-采集的数据-后羿采集器.html

Pro.ID

21510

Title

Double Dealing

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21510

AC

2

Submit

30

Ratio

6.67%

时间&空间限制

  • Time Limit: 16000/8000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    Take a deck of n unique cards. Deal the entire deck out to k players in the usual way: the top card to player 1, the next to player 2, the k-th to player k, the (k+1)-th to player 1, and so on. Then pick up the cards --- place player 1's cards on top, then player 2, and so on, so that player k's cards are on the bottom. Each player's cards are in reverse order --- the last card that they were dealt is on the top, and the first on the bottom.

    How many times, including the first, must this process be repeated before the deck is back in its original order?

    输入

    There will be multiple test cases in the input. Each case will consist of a single line with two integers, n and k (1 ≤ n ≤ 800, 1 ≤ k ≤ 800). The input will end with a line with two 0s.

    输出

    Description

    Take a deck of n unique cards. Deal the entire deck out to k players in the usual way: the top card to player 1, the next to player 2, the k-th to player k, the (k+1)-th to player 1, and so on. Then pick up the cards --- place player 1's cards on top, then player 2, and so on, so that player k's cards are on the bottom. Each player's cards are in reverse order --- the last card that they were dealt is on the top, and the first on the bottom.

    How many times, including the first, must this process be repeated before the deck is back in its original order?

    Input

    There will be multiple test cases in the input. Each case will consist of a single line with two integers, n and k (1 ≤ n ≤ 800, 1 ≤ k ≤ 800). The input will end with a line with two 0s.

    Output

    For each test case in the input, print a single integer, indicating the number of deals required to return the deck to its original order. Output each integer on its own line, with no extra spaces, and no blank lines between answers. All possible inputs yield answers which will fit in a signed 64-bit integer.

    Sample Input

    1 3
    10 3
    52 4
    0 0

    Sample Output

    1
    4
    13

    Source

    样例输入

    1 3
    10 3
    52 4
    0 0

    样例输出

    1
    4
    13

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部