21946_CandyDistribution

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

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

Pro.ID

21946

Title

Candy Distribution

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Kids like candies, so much that they start beating each other if the candies are not fairly distributed. So on your next party, you better start thinking before you buy the candies.

    If there are K kids, we of course need K * X candies for a fair distribution, where X is a positive natural number. But we learned that always at least one kid looses one candy, so better be prepared with exactly one spare candy, resulting in (K * X) + 1 candies.

    Usually, the candies are packed into bags with a fixed number of candies C. We will buy some of these bags so that the above constraints are fulfilled.

    输入

    The first line gives the number of test cases t (0 < t < 100). Each test case is specified by two integers K and C on a single line, where K is the number of kids and C the number of candies in one bag (1 ≤ K, C ≤ 109). As you money is limited, you will never buy more than 109 candy bags.

    输出

    Description

    Kids like candies, so much that they start beating each other if the candies are not fairly distributed. So on your next party, you better start thinking before you buy the candies.

    If there are K kids, we of course need K * X candies for a fair distribution, where X is a positive natural number. But we learned that always at least one kid looses one candy, so better be prepared with exactly one spare candy, resulting in (K * X) + 1 candies.

    Usually, the candies are packed into bags with a fixed number of candies C. We will buy some of these bags so that the above constraints are fulfilled.

    Input

    The first line gives the number of test cases t (0 < t < 100). Each test case is specified by two integers K and C on a single line, where K is the number of kids and C the number of candies in one bag (1 ≤ K, C ≤ 109). As you money is limited, you will never buy more than 109 candy bags.

    Output

    For each test case, print one line. If there is no such number of candy bugs to fulfill the above constraints, print "IMPOSSIBLE" instead. Otherwise print the number of candy bags, you want to buy. If there is more than one solution, any will do.

    Sample Input

    5
    10 5
    10 7
    1337 23
    123454321 42
    999999937 142857133

    Sample Output

    IMPOSSIBLE
    3
    872
    14696943
    166666655

    Source

    样例输入

    5
    10 5
    10 7
    1337 23
    123454321 42
    999999937 142857133

    样例输出

    IMPOSSIBLE
    3
    872
    14696943
    166666655

    提示

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部