eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Candy Distribution

Candy Distribution

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 \textbf{K} kids, we of course need \textbf{K·X} candies for a fair distribution, where \textbf{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 (\textbf{K·X})+\textbf{1} candies. Usually, the candies are packed into bags with a fixed number of candies \textbf{C}. We will buy some of these bags so that the above constraints are fulfilled. \InputFile The first line gives the number of test cases \textbf{t} (\textbf{0} < \textbf{t} < \textbf{100}). Each test case is specified by two integers \textbf{K} and \textbf{C} on a single line, where \textbf{K} is the number of kids and \textbf{C} the number of candies in one bag (\textbf{1} ≤ \textbf{K}, \textbf{C} ≤ \textbf{10^9}). As you money is limited, you will never buy more than \textbf{10^9} candy bags. \OutputFile For each test case, print one line. If there is no such number of candy bugs to fulfill the above constraints, print "\textbf{IMPOSSIBLE}" instead. Otherwise print the number of candy bags, you want to buy. If there is more than one solution, any will do.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
5
10 5
10 7
1337 23
123454321 42
999999937 142857133
Выходные данные #1
IMPOSSIBLE
3
872
14696943
166666655
Источник ACM ICPC German Collegiate Programming Contest 2012