CF BUDDY
← Problems·

1488D · Problemsolving Marathon

1900 · *special, binary search, greedy

Problem: Polycarp has decided to do a problemsolving marathon. He wants to solve ss problems in nn days. Let aia_i be the number of problems he solves during the ii-th day. He wants to find a distribution of problems into days such that:

  • aia_i is an integer value for all ii from 11 to nn;
  • ai1a_i \ge 1 for all ii from 11 to nn;
  • ai+1aia_{i + 1} \ge a_i for all ii from 11 to n1n-1;
  • ai+12aia_{i + 1} \le 2 \cdot a_i for all ii from 11 to n1n-1;
  • ana_n is maximized.

Note that a1a_1 can be arbitrarily large.

What is the largest value of ana_n Polycarp can obtain?

Input Format: The first line contains a single integer tt (1t10001 \le t \le 1000) — the number of testcases.

Then the descriptions of tt testcases follow.

The only line of each testcase contains two integers nn and ss (1ns10181 \le n \le s \le 10^{18}) — the number of days and the number of problems Polycarp wants to solve.

It's guaranteed that the distribution always exists within the given constraints.

Output Format: For each testcase print a single integer — the maximum value of ana_n.

Note: In the first testcase there is only one distribution: [15][15].

In the second testcase the distribution that maximizes ana_n is: [2,3,4][2, 3, 4].

In the third testcase the distribution that maximizes ana_n is: [2,4][2, 4]. [3,3][3, 3] is a valid distribution but an=3a_n=3 which is smaller than 44. [1,5][1, 5] is not a valid distribution because 5>215 > 2 \cdot 1.

Sample Cases

Case 1

Input

3
1 15
3 9
2 6

Output

15
4
4

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback