CF BUDDY
← Problems·

1455B · Jumps

1200 · constructive algorithms, math

Problem: You are standing on the OX\mathit{OX}-axis at point 00 and you want to move to an integer point x>0x > 0.

You can make several jumps. Suppose you're currently at point yy (yy may be negative) and jump for the kk-th time. You can:

  • either jump to the point y+ky + k
  • or jump to the point y1y - 1.

What is the minimum number of jumps you need to reach the point xx?

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

The first and only line of each test case contains the single integer xx (1x1061 \le x \le 10^6) — the destination point.

Output Format: For each test case, print the single integer — the minimum number of jumps to reach xx. It can be proved that we can reach any integer point xx.

Note: In the first test case x=1x = 1, so you need only one jump: the 11-st jump from 00 to 0+1=10 + 1 = 1.

In the second test case x=2x = 2. You need at least three jumps:

  • the 11-st jump from 00 to 0+1=10 + 1 = 1;
  • the 22-nd jump from 11 to 1+2=31 + 2 = 3;
  • the 33-rd jump from 33 to 31=23 - 1 = 2;

Two jumps are not enough because these are the only possible variants:

  • the 11-st jump as 1-1 and the 22-nd one as 1-1 — you'll reach 011=20 -1 -1 =-2;
  • the 11-st jump as 1-1 and the 22-nd one as +2+2 — you'll reach 01+2=10 -1 +2 = 1;
  • the 11-st jump as +1+1 and the 22-nd one as 1-1 — you'll reach 0+11=00 +1 -1 = 0;
  • the 11-st jump as +1+1 and the 22-nd one as +2+2 — you'll reach 0+1+2=30 +1 +2 = 3;

In the third test case, you need two jumps: the 11-st one as +1+1 and the 22-nd one as +2+2, so 0+1+2=30 + 1 + 2 = 3.

In the fourth test case, you need three jumps: the 11-st one as 1-1, the 22-nd one as +2+2 and the 33-rd one as +3+3, so 01+2+3=40 - 1 + 2 + 3 = 4.

Sample Cases

Case 1

Input

5
1
2
3
4
5

Output

1
3
2
3
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