405081: GYM101778 B Ran and the Lock Code

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

Description

B. Ran and the Lock Codetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Two days ago, a woman called Fumiyo Edogawa knocked the door of Kogoro Mouri home and claimed that she is Conan's mom. Fumiyo introduced herself as Conan's mother and used fake documents to prove this. Conan, Kogoro Mouri, and his daughter Ran believed her. So, Conan went with her.

Ran was worried about Conan. After investigations, Ran discovered that Conan has been kidnapped! Ran called the police and they helped her to find Conan's location. When they arrived at that location, Ran shocked because she discovered that Conan is detained inside a locked coffin.

After examining the coffin, Ran discovered that it is locked using a modern electronic lock. Ran can open the lock only by solving T mysteries. In each mystery, Ran is giving two numbers n and a, and she needs to find the maximum number of distinct elements that can exist in a list of n positive elements with an average equals to a.

Ran knows that time is running out of her, and she must expedite in solving the mysteries to get Conan out of the coffin before his breath stopped. Ran asked you to help her in solving the mysteries. Will you leave Conan to die smothered or will you help Ran solving the mysteries?

Input

The first line contains an integer T (1 ≤ T ≤ 105), in which T is the number of mysteries.

Then T lines follow, giving the mysteries. Each line contains two integers n and a (1 ≤ n, a ≤ 109), in which n is the number of elements in the list, and a is the required average of that list.

Output

For each test case, print a single line containing the maximum number of distinct elements that can exist in a list of n positive elements with an average equals to a.

ExampleInput
3
2 4
5 1
8 4
Output
2
1
7
Note

The average of a list of n elements x1, x2, ..., xn is defined as the ratio between the sum of the n elements and n. More formally:

In the first test case, Ran is asked to find the maximum number of distinct elements that can exist in a list of 2 positive elements with an average equals to 4. Ran can choose a list such as [3, 5]. So, the number of distinct elements is 2.

加入题单

算法标签: