406759: GYM102535 P The Only Level

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

P. The Only Leveltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

A secret agent... to be one you have pushed both your physical and intellectual capacities, immersing yourself in the art of espionage. It is now time to prove your worth.

Your name isn't Mario but you end up falling down from a pipe.

You find an elephant in a room.

It speaks.

You expect a Sphinx to give out a riddle in this scenario, but the elephant gives you no time to be confused as it tells you:

"If you want to be a spy, you must pass the test."

After a moment's hesitation, you find the words to reply. "Yes, this is what I came here for. But is there anything else that I must do?"

"No, this is the only level," the elephant assures you.

It gives you the test:

" The digital sum of an integer in base $$$b$$$ is the sum of its digits when it is written in base $$$b$$$. The digital root of an integer in base $$$b$$$ is the unique digit obtained by repeatedly computing the digital sum in base $$$b$$$ until only one digit remains.

Let $$$f_b(k)$$$ be the digital root of the integer $$$k$$$ in base $$$b$$$.

We say that the pair $$$(k,b)$$$ is cool if and only if $$$(f_b(0), f_b(k), f_b(2k), \ldots, f_b((b-1)k))$$$ is a permutation of $$$(0, 1, 2, \ldots, b-1)$$$.

Given $$$k$$$ and $$$b$$$, is $$$(k,b)$$$ a cool pair? "

Input

The first line of input contains $$$t$$$, the number of test cases.

Each test case consists of a single line containing two space-separated integers $$$k$$$ and $$$b$$$.

Constraints

$$$1 \le t \le 10^5$$$

$$$1 \le k \le 10^{15}$$$

$$$2 \le b \le 10^{15}$$$

Output

For each test case, output a single line containing the string:

  • "COOL" (without the quotes) if $$$(k, b)$$$ is a cool pair;
  • "NOT COOL" (without the quotes) if $$$(k, b)$$$ is not a cool pair.
ExampleInput
2
10 7
7 10
Output
NOT COOL
COOL

加入题单

上一题 下一题 算法标签: