We need to understand the problem.
Joy can jump up stairs with a magical stepping pattern. Initially, he can take 1 or 2 steps. After each jump of x steps, the next jump can be either x or x+1 steps (depending on his choice). He must land exactly on the nth step. Find the minimum number of jumps.
So this is a sequence of jumps where each jump length is either the same as previous or increased by 1 (if chosen), starting from first jump length either 1 or 2.
Goal: Given total steps n, minimize number of jumps.
This is reminiscent of the problem "Minimum number of jumps to reach sum S with step lengths that can increase by at most 1, starting from 1 or 2" – essentially like constructing a sequence that sums to n with lengths that follow: a1 ∈ {1,2}, and for i>1, a_i ∈ {a_{i-1}, a_{i-1}+1}. Minimize the number of terms.
We need to find the minimal k such that there exists a sequence of positive integers a1,...,ak satisfying:
- a1 = 1 or 2.
- For i=2..k: a_i = a_{i-1} or a_{i-1}+1.
- Sum_{i=1}^k a_i = n.
Minimize k.
Since we can always choose to increase or stay same. To minimize the number of jumps, we would like each jump as large as possible. But there is a constraint: The step lengths can only increase by at most 1 each jump, starting from a small initial value. So the maximum sum for a given number of jumps k, given we start with some initial step and choose increases optimally, will be the maximum total steps we can cover in k jumps. Similarly, there is a minimum sum for k jumps (if we always stay at the minimum possible lengths). So for given n, we need to find smallest k such that n is between min_sum(k) and max_sum(k). Then answer is k.
But careful: There's also the choice of initial step: 1 or 2. So for each k, there are two families: start with 1, or start with 2. The maximum sum for k jumps starting with 1 is: we want to maximize sum, so we should increase as much as possible. Since we can increase by at most 1 each step, the maximum lengths we can achieve are: a1=1, a2=2, a3=3, ..., a_k = k? Let's check: Starting with 1, next can be 1 or 2, to maximize we choose 2, then next can be 2 or 3, choose 3, ... so yes, we can have a_i = i for i=1..k. That sum = 1+2+...+k = k(k+1)/2.
But is that allowed? The rule: after a jump of x, the next can be x or x+1. So starting at 1, we can go to 2, then to 3, etc. So indeed the maximum sum for start=1 is k(k+1)/2. However, note that we must end exactly on nth step, and we can also choose to not increase at some steps. So the maximum sum is achieved by always increasing when possible. However, there is a nuance: Could we exceed that by starting with 2? Let's compute.
Start with 2: a1=2. Then a2 can be 2 or 3; to maximize sum choose 3. Then a3 can be 3 or 4, choose 4. So a_i = i+1? Let's list: a1=2, a2=3, a3=4, ..., a_k = k+1? Check: For i=1, a1=2 = 1+1? Actually if we set a_i = i+1, then i=1 gives 2, i=2 gives 3, ... i=k gives k+1. So sum = (2 + (k+1)) * k /2 = (k+3)*k/2 = k(k+3)/2. But is it possible to have a_i = k+1 at the last jump? Starting from 2, we increase each time: after a1=2, we take a2=3 (increase by 1), then a3=4 (increase by 1), after i-1 steps we increase to i+1? For k jumps, the maximum is indeed a_i = 1 + i? Wait: a_i start from 2, and each step we increase by 1, so after (i-1) increases, a_i = 2 + (i-1) = i+1. So yes. So sum_max_start2 = sum_{i=1}^{k} (i+1) = k(k+1)/2 + k = k(k+3)/2.
But is there any other pattern that yields even larger sum? What if we start with 1, but then at some point we increase more than 1? Not allowed. So those are maxima.
Now what about minima? For a given k, to minimize sum, we want to keep jumps as small as possible. For start=1: a1=1, then a2 can be 1 (stay same) or 2; to minimize sum choose 1, and similarly all subsequent a_i =1. So min sum = k*1 = k. But is that always allowed? The rule: after a jump of x, next can be x or x+1. So if we stay at 1 each time, it's allowed because from x=1, we can choose x again (1). So min sum_start1 = k.
For start=2: a1=2, then to minimize sum, we should stay at 2 each time (since we can choose x). So min sum_start2 = 2*k = 2k.
But there might be hybrid sequences that yield sums in between these extremes, possibly any integer between min and max? Typically, for such step increment constraints, all intermediate sums are achievable, as we can decide when to increase. So the set of achievable sums for given k and start should be all integers from min_sum to max_sum inclusive. But we need to confirm that there is no gaps. Let's reason: Starting from a given start, the sequences are defined by at each step we either stay or increase. The sum is monotonic with respect to the times we increase. If we increase at some specific steps, the sum increases. It seems plausible that by choosing which steps to increase, we can achieve all sums in the range. However, we need to be careful: When we increase, the increments affect later jumps as well. This is reminiscent of representing numbers as sum of "almost arithmetic progression" where increments can be applied early. Usually, these sets are contiguous. But let's test small k.
k=2, start=1: Possible sequences: (1,1) sum=2; (1,2) sum=3. So range 2 to 3, all integers covered? 2 and 3, yes.
k=2, start=2: (2,2) sum=4; (2,3) sum=5, range 4-5, yes.
k=3, start=1: possibilities: (1,1,1)=3; (1,1,2)=4? Wait: after (1,1) we have a2=1, then a3 can be 1 or 2 => (1,1,2)=4; (1,2,2) sum=5? (1,2,2): after (1,2) a2=2, a3 can be 2 or 3 => (1,2,2)=5; (1,2,3)=6. Also (1,1,1)=3, (1,1,2)=4, (1,2,2)=5, (1,2,3)=6. Also maybe (1,1,?) only those. So sums 3,4,5,6 contiguous.
Start=2, k=3: (2,2,2)=6; (2,2,3)=7; (2,3,3)=8; (2,3,4)=9? Let's check: (2,3,3) allowed? after (2,3), a3 can be 3 or 4 => (2,3,3)=8; (2,3,4)=9. Also (2,2,2)=6, (2,2,3)=7, (2,3,3)=8, (2,3,4)=9, all contiguous 6-9. Good.
So it appears achievable sums form continuous intervals. Thus for a given start and k, all sums in [min, max] are reachable.
Therefore, to find minimum jumps for given n, we need to find smallest k such that n is within either the interval for start=1 or start=2.
We consider both possibilities: For a given k, the achievable sums are:
- start=1: from k to k(k+1)/2.
- start=2: from 2k to k(k+3)/2.
If n lies in either of these intervals (inclusive), then k jumps are possible.
We need the minimum k.
Thus, we can precompute for n up to 1e5, or compute directly.
Since t up to 100, n up to 1e5, we can for each test case, loop k from 1 upwards until we find a k satisfying condition. But n can be up to 1e5, and k maximum would be about sqrt(2n) ~447 for start=1 max sum ~k^2/2; but start=2 may have larger max sum for same k? Actually start=2 max sum = k(k+3)/2 ≈ k^2/2 + 1.5k. So still O(sqrt(n)). That's fine. But we can also derive a formula.
Alternatively, we could derive the minimal k by solving inequalities.
We need the minimal k such that:
Either (k <= n <= k(k+1)/2) OR (2k <= n <= k(k+3)/2).
But note that for small n, maybe both conditions hold? But we want minimal k. So we can iterate k from 1 to, say, while maybe min_sum_start1 <= n? Actually min_sum_start1 increases with k: it's k; min_sum_start2 is 2k. For a given n, as k increases, the intervals shift.
But careful: For very small n, like n=1, what is answer? Let's check: if n=1, can he reach step 1? Starting, he can take 1 or 2 steps. If he takes 1 step, he lands exactly on step 1, so jumps=1. So answer=1. Our condition: For k=1, start=1: min=1, max=1(2)/2=1 => n=1 inside; also start=2: min=2, max=2(4)/2? Actually k=1, start=2: min=2, max = 1*(1+3)/2 = 2, so n=1 not in that. So k=1 works. Good.
n=2: can be reached with one jump of 2 (start=2). Also possible with two jumps of 1? But min jumps is 1. For k=1: start=1 gives max=1, so 2 not in; start=2 gives min=2 max=2, so yes. So answer 1. Our condition: k=1 works (start=2). So answer 1. matches sample? Sample input 2 gave output 1 for n=2, correct.
n=3: Sample output 2. Let's see: With one jump: can we jump 3? No, only 1 or 2 initially, so not possible. Two jumps: possible sequences? Starting 1 then 2 (1+2=3) => 2 jumps; also 2 then 1? After first 2, next can be 2 or 3; can't be 1. So only that. So answer 2. Our condition: k=1? Not possible. k=2: start=1: min=2, max=3 => includes 3; start=2: min=4, max=5 => no. So yes.
So condition works.
Thus problem reduces to finding smallest integer k such that:
n ≤ max_start1(k) = k(k+1)/2, and also n ≥ k (if using start=1) OR n ≤ max_start2(k) = k(k+3)/2 and n ≥ 2k (if using start=2).
But note: For a given k, if n is less than min_start1 (i.e., n < k) and also less than min_start2 (n < 2k), then obviously k too large? Actually if k is too large, min_sum exceed n, but we want n to be at least the min of the interval. So the condition for feasibility is that n is between min and max for some start.
Therefore we need to find minimal k where either condition holds.
Observation: Since min_start1 = k, min_start2 = 2k. For a given n, the smallest possible k for start=1 is at least ceil(n / something?) Not straightforward.
We can derive bound: For start=1, the maximum sum is roughly k^2/2, so k needed is about sqrt(2n). For start=2, k roughly sqrt(2n) as well but slightly less because max sum is larger? Actually for same k, start=2 covers higher totals. So maybe for some n, start=2 requires fewer jumps? Compare: For start=1, to reach a given n, we need k such that n ≤ k(k+1)/2. For start=2, we need n ≤ k(k+3)/2. For the same k, start=2 can cover larger n. So sometimes a smaller k might work with start=2 but not start=1. Example: n=4. For k=2: start=1 max=3 (<4), not enough; start=2 max=5, min=4 => n=4 works. So answer k=2? Check: n=4: can we reach in 2 jumps? Starting 2 then 2? That's 2+2=4, yes (2 jumps). So answer 2. That matches.
n=5: k=2: start=1 max=3 no; start=2 max=5 min=4 -> includes 5 => k=2? Check: 2+3=5 => 2 jumps. So answer 2. Good.
n=6: k=2: start=2 max=5 <6, not; start=1 max=3. So k=3? k=3: start=1 max=6 min=3 => includes 6 => 3 jumps. But could we reach 6 in 2 jumps? 2+? after 2 can be 2 or 3 => sums: 2+2=4, 2+3=5. 1+? after 1 can be 1 or 2: 1+1=2, 1+2=3. So no. So answer 3. That's plausible.
But also start=2 k=3: min=6 max=9, includes 6, also 3 jumps. So both. So minimal k is 3.
Thus answer is min k such that n ≤ max(k) with appropriate min condition.
Now to compute efficiently: Since n up to 1e5, we can precompute for k from 1 to maybe 500 (since for k=500, max_start2 = 500*503/2 = 125750 > 1e5, so safe). Then for each test case, loop k from 1 upwards until condition met.
But t ≤ 100, looping up to 500 per test is fine (500*100=50k). Alternatively, solve quadratic inequality.
We could solve for k from start=1: Find smallest integer k such that k(k+1)/2 >= n AND also n >= k. But note: if n < k, then even if max >= n, min > n, so cannot. However, if k(k+1)/2 >= n, automatically k <= n? Let's check: For k(k+1)/2 >= n, does it guarantee k <= n? For k > n, k(k+1)/2 > n? Possibly but also k > n. Example: n=5, k=4: 4*5/2=10 >=5, but k=4 > n, so min_start1=4, but n=5, so 5 >= 4? Actually min=4 <= 5, so condition holds. Wait: For k=4, min_start1=4, max=10, so n=5 is within. But can we actually reach 5 with 4 jumps starting from 1? Let's check possible sequences: For k=4, can we sum to 5? Starting 1, we need three more jumps. With min sum=4, max sum=10. Can we get 5? Possibly: 1,1,1,2? That's 5? 1+1+1+2=5, allowed? Sequence: a1=1, a2 can be 1, a3 can be 1, a4 can be 1 or 2 from a3=1. So (1,1,1,2)=5, yes. So indeed 4 jumps works. But we want minimal jumps, which is 2 for n=5? Actually earlier we found n=5 answer 2. So k=4 is not minimal. So for n=5, k=2 works (via start=2). So we need to consider both starts. For start=1, k=2 does not work because max=3 <5, but k=4 works. But we also have start=2 k=2 works, so answer is 2. So minimal overall k is the smallest across both starts.
So approach: For each k starting from 1, check if (k <= n <= k(k+1)/2) OR (2k <= n <= k(k+3)/2). If yes, output k and break.
But is there any scenario where a larger k is needed because for smaller k neither condition holds, but for some larger k, one condition holds? Yes. So iteration from 1 upwards works.
Complexity: For n up to 1e5, maximum k needed might be for n near 1e5 with start=1? The maximum k when using start=1: we need k such that k(k+1)/2 >= n. Solve k ≈ sqrt(2n) ≈ 447. For start=2, max k needed: solve k(k+3)/2 >= n, k ≈ sqrt(2n) as well (slightly smaller). So max k ~447. So loop up to 447 per test, trivial.
But careful: For n=0? Problem says 0 < n ≤ 10^5. So n positive. No zero.
Thus solution is simple.
But let's double-check boundaries: For n = 1, k=1: start1 min=1 max=1 -> ok. So answer 1.
n = 2: k=1: start2 min=2 max=2 -> ok. answer 1.
n = 3: k=1: no; k=2: start1 min=2 max=3 -> ok. answer 2.
n = 4: k=2: start2 min=4 max=5 -> ok. answer 2.
n = 5: k=2: start2 min=4 max=5 -> ok. answer 2.
n = 6: k=2: no; k=3: start1 min=3 max=6 -> ok. answer 3.
n = 7: k=3: start1 max=6 <7; start2 min=6 max=9 -> includes 7, so answer 3? Check: Can we reach 7 in 3 jumps? Starting 2: 2+?+? =7. Possible sequences: (2,2,3)=7; (2,3,2)? Not allowed because after 3 we can only 3 or 4, not 2. So (2,2,3) works: 2+2+3=7. So 3 jumps. Could 2 jumps work? 2+? after 2: 2+2=4, 2+3=5; 1+? after 1: 1+1=2, 1+2=3. So no. So answer 3. Good.
n = 8: k=3: start2 min=6 max=9 includes 8 -> 3 jumps? (2,3,3)=8 or (2,2,4)? 2+2+4=8 but after 2, we can go to 2 or 3; if we have (2,2,?) after 2, we can go to 2 or 3, not 4. So (2,2,4) not allowed because a3 must be 2 or 3 from a2=2. So (2,3,3) works: 2+3+3=8. So yes 3 jumps. So answer 3.
n = 9: k=3: start2 max=9 includes 9 -> 3 jumps (2,3,4)=9; also possible (2,2,5?) not allowed. So answer 3.
n = 10: k=3: start2 max=9 <10; start1 max=6; no. k=4: start1 min=4 max=10 includes 10? Max=4*5/2=10, min=4. So n=10 within -> answer 4? Check: 1+2+3+4=10, 4 jumps. Could start=2 give k=4? min=8 max=14, includes 10, but k=4 is larger than 4 anyway, but we want minimal. So answer 4. Could there be a 3-jump solution? 2+3+5? Not allowed because after 3, we can only do 3 or 4; 2+3+4=9, 2+3+5 no; 2+4+? after 4 can be 4 or 5; 2+4+4=10? but can we have 2 then 4? Starting 2, then a2 can be 2 or 3; cannot jump 4 directly. So no. So answer 4 seems correct.
Now we need to ensure that for k large, the intervals cover all numbers from min to max. We argued they are contiguous, which seems plausible and aligns with small examples. Let's try to prove quickly: For a given start and k, the set of achievable sums is exactly all integers from min_sum to max_sum. This can be proven by induction or by noticing that we can adjust the sequence by shifting an increase later or earlier to change sum by 1. It's typical for such problems. So we trust.
Therefore algorithm: For each test case, for k = 1,2,... until condition met:
- if (k <= n && n <= k*(k+1)/2) break;
- else if (2k <= n && n <= k(k+3)/2) break;
output k.
But note: the first condition: k <= n, but if n is less than k, it's automatically false. Similarly second: 2k <= n.
Now we need to handle integer overflow? k up to maybe 500, k*(k+1) up to 500*501=250500, half is 125250, within 32-bit int. But n up to 100k, so fine.
Edge cases: For n very large near 100k, k might be up to around 447, product ~200k, still fine.
Now is there any possibility that neither condition is ever true? Since as k increases, max sums increase without bound, and min sums also increase. For any n, there will be some k where min_sum <= n <= max_sum? Possibly need to consider both starts; but min_sum_start1 = k, for k = n, min = n, max = n(n+1)/2 which is >= n, so condition holds for k = n (since n is between k and max). So there always exists a solution: just take all jumps of size 1 if start=1, but wait: if start=1, we can take k jumps all of size 1 only if we start with 1 and never increase. That yields sum = k. So for any n, we can take n jumps of 1, that sum n. So k = n is always possible. But is it allowed? Starting with 1, then each subsequent jump can be 1 (since staying same is allowed). So yes, we can always achieve exactly n in n jumps by all ones. So there is always a solution. The minimal jumps is at most n. And our iteration will eventually hit k = n which satisfies start=1 condition (since n <= n(n+1)/2 obviously and n >= n). But we don't need to iterate that far because we will find a smaller k earlier. Since max sum grows quadratically, for n up to 100k, the required k is at most ~447. So safe.
Thus solution straightforward.
But wait, check n=100000: We can find k such that k(k+1)/2 >= 100000 => k ≈ 447 (since 447448/2 = 447224 = 100128? Let's compute: 447448=200256, half=100128, so yes >=100000. And min for start=1 = 447, which is <=100000, so condition holds. So k=447 works. However, maybe start=2 yields smaller k? For start=2, we need k(k+3)/2 >=100000. For k=446, 446449/2 = 446224.5 = 100, something? 446449 = 200,? 446449 = 446400=178400, 44649=21854, sum=200254, half=100127. Actually 446449 = 200,? Let's compute accurately: 449446 = 449400=179600, 44946=20654, total=200254, half=100127. So for k=446, max=100127, min=892, condition holds. So k=446 works. Could be even smaller? For k=445, 445448/2 = 445*224 = 99680, <100000, so not. So minimal k is probably 446 or 447. But we need to check if start=2 with k=446 min is 892 <=100000, max=100127, includes 100000, so yes. So answer 446. But is start=1 with k=447 also possible? k=447 is larger, so min is 447. So 446 is smaller. So answer would be 446. But wait, does start=2 with k=446 require n >= 2k = 892, which is satisfied, so condition ok. So indeed minimal is 446. So answer for n=100000 is 446? Let's test with smaller n: n=100000, maybe there's even smaller k? Let's approximate: start=2 max ~ k^2/2 + 1.5k, so solving k^2/2 ≈ n gives k≈447, so 446 is plausible. So fine.
Thus algorithm yields correct.
Now ensure we handle t up to 100, no issues.
We must also consider that the initial step can be either 1 or 2; but what about the possibility of starting with 0? No.
Thus final solution.
But wait, maybe there is a nuance: The description: "Initially he can take 1 or 2 steps. If he jumps x steps at a time then in the next step he can climb either x or x+1 steps depending on his choice and he must reach exactly on n'th step." It says "jumps x steps at a time then in the next step he can climb either x or x+1 steps". So the next step's length is either the same as the previous step (x) or one more (x+1). So yes.
Now let's confirm more examples:
n=11: k=4? start1 max=10 <11; start2 max=4*7/2=14, min=8, includes 11 -> k=4. But maybe k=4 works with start=2: sequences: 2+2+3+4=11? 2+2+3+4=11? That's 2+2=4, +3=7, +4=11, possible? Starting 2, then a2=2 (allowed), a3 from a2=2 can be 2 or 3 -> choose 3, a4 from a3=3 can be 3 or 4 -> choose 4, sum=11. So yes. Could k=3? start2 max=9, start1 max=6, so no. So answer 4.
n=12: k=4: start2 max=14 includes 12, min=8, so yes 4? 2+2+3+5? Not allowed. Let's find a sequence: need sum 12. Could be 2+3+3+4=12? 2+3=5, +3=8, +4=12. Sequence: a1=2, a2=3 (increase), a3=3 (stay), a4=4 (increase from 3). Allowed. So answer 4. Could there be 5 jumps with start=1 to do 12 in 5? But minimal is 4. So ok.
n=13: k=4: start2 max=14, includes 13. Sequence: 2+3+4+4=13? 2+3=5, +4=9, +4=13, allowed: after 4 can stay at 4. So 4 jumps. So answer 4.
n=14: k=4: start2 max=14 includes 14. Sequence: 2+3+4+5? But from a3=4 can go to 5 => 2+3+4+5=14, yes. So 4 jumps.
n=15: k=4: start2 max=14 <15; start1 max=10; no. k=5: start1 max=15, min=5 includes 15? 56/2=15, yes. Also start2 max=58/2=20, min=10 includes 15. So answer 5. Check: 1+2+3+4+5=15 (5 jumps). Could we do 4 jumps? 2+3+4+6? Not allowed. 2+3+4+5=14; 2+3+4+6 not possible; 2+3+5+5? after 4 can't go to 5? Actually (2,3,5,5) not allowed because from 3 to 5 is +2. So no. So answer 5.
Seems consistent.
Now consider n=100: approximate sqrt(200) ~14.14. Actually k(k+1)/2 >=100 => k≈14 (1415/2=105) so k=14 works for start=1? min=14 <=100, max=105 >=100, so k=14 works. For start=2: k(k+3)/2 >=100 => try k=13: 1316/2=104, min=26 <=100, so k=13 works. So answer 13. Check: 2+3+4+...+15? Actually for k=13, a_i = i+1? Sum=1314/2 +13 = 91+13=104? Wait compute: 13(13+3)/2 =13*16/2=104. So max sum 104. So 100 is reachable. So answer 13. So start=2 gives better sometimes.
Thus algorithm fine.
Now implement.
But before finalizing, let's double-check the condition for start=1: min_sum = k, max_sum = k(k+1)/2. However, is it always possible to achieve exactly the min sum? Yes, by all ones. But note: if start=1, all jumps 1 works? Starting with 1, then next can be 1, yes. So that's fine. For start=2, min sum = 2k, achieved by all twos. But is all twos allowed? Starting 2, then a2 can be 2 (stay), a3 can be 2 (stay), etc. So yes.
Now consider extreme: n = 2k exactly? That's min start2. So valid.
Now for start=1, the condition also requires that the sum can be exactly n for any n between k and k(k+1)/2 inclusive. As argued, it's continuous. Could there be a gap? Possibly if the allowed sequences don't allow certain sums due to parity? Let's test k=4 start=1: min=4, max=10. According to our earlier enumeration, sums 4,5,6,7,8,9,10 should all be possible. We saw 4 (1,1,1,1), 5 (1,1,1,2), 6 (1,1,2,2) or (1,2,1,2?) But note sequence must follow step rule; can we get 7? 1,2,2,2? 1+2+2+2=7, is that allowed? a1=1, a2=2 (increase), a3 from 2 can be 2 or 3, choose 2, a4 from 2 can be 2 or 3, choose 2 => sum=7, yes. 8: 1,2,2,3? sum=8; 1,2,3,2 not allowed due to decreasing? Actually from 3 cannot go to 2. So but 1,2,3,2 not allowed. But we can do 1,1,2,4? Not allowed because from 2 cannot go to 4. Let's try to find a sequence for sum 8: 1,2,3,2 not allowed; 1,3,? start 1 then 3 not allowed (since from 1 can only go to 1 or 2). So possible sequences: (1,2,2,3) works? 1+2=3, +2=5, +3=8. Check: a1=1, a2=2 (increase), a3=2 (stay), a4 from a3=2 can be 2 or 3 -> choose 3 => sum 8, yes. Also (1,2,3,2) not allowed. (1,1,3,3) not allowed because from 1 to 3 not allowed. (1,3,3,1) no. So 8 reachable. 9: (1,2,3,3) sum=9; (1,2,2,4) not allowed; (1,3,3,2) no. So 9 reachable. 10: (1,2,3,4) sum=10. So all sums 4-10 reachable. Good.
What about start=2 k=4: min=8, max=14. Are all sums from 8 to 14 reachable? Let's test: 8 (2,2,2,2), 9 (2,2,2,3) sum=9, 10 (2,2,3,3) or (2,3,2,3?) not allowed because from 3 to 2 not allowed. But (2,2,3,3) works: a1=2, a2=2, a3 from 2 can be 2 or 3 -> choose 3, a4 from 3 can be 3 or 4 -> choose 3 => sum=10. 11 (2,2,3,4) works? 2+2+3+4=11: allowed: a1=2, a2=2, a3=3 (increase), a4 from 3 can be 3 or 4 -> choose 4 => sum=11. 12 (2,3,3,4) or (2,2,4,4)? (2,2,4,4) not allowed because from 2 to 4 not allowed. (2,3,3,4): a1=2, a2=3 (increase), a3=3 (stay), a4 from 3 can be 3 or 4 -> choose 4 => sum=12. 13 (2,3,4,4): a1=2, a2=3, a3=4 (increase), a4 stay 4 => sum=13. 14 (2,3,4,5) => sum=14. Also 15? max is 14. So all sums 8-14 reachable. So continuous.
Thus algorithm stands.
Now we can proceed to code.
But I want to confirm that there is no alternative initial step besides 1 or 2. The problem says "Initially he can take 1 or 2 steps." So yes.
Now we output the minimum number of jumps.
Implementation details:
Read t.
For each test:
read n.
k=1
while True:
if (k <= n and n <= k*(k+1)//2) or (2k <= n and n <= k(k+3)//2):
print(k)
break
k += 1
But be careful: The second condition uses k*(k+3)//2. Let's compute integer division after multiplication.
Complexities fine.
But we must be cautious: For k=1, first condition: k<=n and n <=1 -> n=1 only. Second: 2k <= n and n <=1(4)/2=2 -> for n=2, 2<=2 and 2<=2 -> true. So works.
Edge case: n=0? not present.
Now what about n=44700? We'll compute.
Now maybe there is a direct formula to compute k without loop. But loop is okay.
But note: t up to 100 and n up to 100k, so worst-case loop 447 * 100 = 44700, trivial.
We could also precompute for each n the minimal k via DP or precomputed table, but not necessary.
However, there is a subtlety: The condition checks both starts. But we need to ensure that we don't miss cases where a smaller k is possible with start=1 even though min condition fails? Actually if n < k, then it's impossible because sum of k jumps starting at 1 is at least k (since each jump at least 1). So condition k <= n is necessary. So it's fine.
Now we should confirm that there is no scenario where start=1 or start=2 might allow sum exactly n even if n is less than min? Impossible because each jump is at least 1 (or 2 for start=2). So min is indeed lower bound.
Thus answer.
Now test some random values to ensure consistency with brute force.
We can attempt to manually test a few more:
n=20: find smallest k.
k such that start2 condition: need k(k+3)/2 >=20. Let's compute:
k=5: 5*8/2=20, min=10, includes 20? max=20, n=20 equals max, so condition holds, k=5. So answer 5. Check: 2+3+4+5+6=20? Actually a_i for k=5 start=2 max: a1=2, a2=3, a3=4, a4=5, a5=6 sum=20. That's 5 jumps. Could k=4? start2 max=14 <20; start1 max=10 <20. So k=5 is minimal.
n=21: k=5: start2 max=20 <21; start1 max=10; no. k=6: start1 max=67/2=21, min=6, includes 21? max=21, n=21, so k=6 works. Also start2 max=69/2=27, min=12 includes 21. So answer 6. Check: 1+2+3+4+5+6=21, 6 jumps. So fine.
n=22: k=6: start1 max=21 <22; start2 max=27 includes 22, min=12, so k=6 works. So answer 6? Check sequence: 2+3+4+5+6+2? Not allowed because after 6 can't go to 2. Need sum 22 with 6 jumps starting at 2. Could we? 2+3+4+5+6+2 not allowed; 2+3+4+5+6+? from 6 we can only do 6 or 7. So if we do 2+3+4+5+6+7=27 too high. But we don't have to always increase; we can also stay. Let's find sequence: 2+3+4+5+6+? from 6 we can do 6 => sum=2+3+4+5+6+6=26. Too high. 2+3+4+5+5+? from 5 can do 5 or 6: 2+3+4+5+5+? Suppose we do 2,3,4,5,5,? from 5 to ? can be 5 or 6: if we do 5 => total 2+3+4+5+5+5=24; if 6 => 25. 2,3,4,4,4,? = 2+3=5,+4=9,+4=13,+4=17,+? from 4 can be 4 or 5 => total 21 or 22. So 2,3,4,4,4,5 = 2+3+4+4+4+5 = 22? 2+3=5, +4=9, +4=13, +4=17, +5=22, yes. Sequence: a1=2, a2=3 (increase), a3=4 (increase), a4=4 (stay), a5=4 (stay), a6 from a5=4 can be 4 or 5 -> choose 5. All allowed. So indeed 6 jumps. So answer 6.
Thus condition works.
Now we need to ensure that for k=6, start2 min = 2k =12, n=22 >=12, max=27, so condition holds, but is it always possible to achieve any integer between? We gave an example for 22, so seems plausible.
Now we can proceed.
But let me consider if there is any scenario where the condition might hold but actually not achievable because the parity or something? I think it's all achievable. Let's try to construct a general proof: For start=1, the set of sums is exactly all integers from k to k(k+1)/2. This is a known combinatorial fact about sequences with increments of at most 1 from start 1 (called "restricted growth strings"?). One can map to compositions with parts increasing by at most 1. There is known that the number of ways to write n as sum of k positive integers with a_i - a_{i-1} ∈ {0,1} and a_1=1 is equal to something. But more importantly, the range is contiguous. We can argue by induction: For k=1, set {1}. Assume for k, we have all sums from k to S_k = k(k+1)/2. For k+1, we consider sequences of length k+1. The last step a_{k+1} is either a_k or a_k+1. So the total sum = sum of first k + a_{k+1}. By induction, the sum of first k can be any integer between k and S_k. Also, the possible a_{k+1} depends on a_k. But we can show that the achievable totals cover from (k+1) to S_{k+1} = (k+1)(k+2)/2. The minimal is when sum of first k is k and a_{k+1}=1? But a_{k+1} must be at least 1? Actually from a_k=1, we can choose a_{k+1}=1 or 2. So minimal sum for k+1 is k+1 (when a_{k+1}=1). So min = k+1. Max is S_k + (a_k+1) where a_k is max possible for length k which is k. So max = S_k + (k+1) = k(k+1)/2 + k+1 = (k+1)(k+2)/2. Now we need to show that all integers in between are achievable. For each total T in [k+1, S_{k+1}], we can subtract a possible last step value (either a_k or a_k+1) and check that remainder is within [k, S_k]. Since a_k depends on the sequence, but we can probably adjust. More concretely, we can show that the set is contiguous because as we increase the number of increases in the sequence, sum increases by 1 each time (maybe). For start=1, the total sum is k plus the number of times we increase (the "increments") because each increase adds 1 to all subsequent jumps? Actually, the sum for a sequence can be expressed as: Let the jumps be a_1=1, and for i>=2, a_i = a_{i-1} + d_i, where d_i ∈ {0,1}. Then a_i = 1 + sum_{j=2}^{i} d_j. The total sum = sum_{i=1}^{k} a_i = k*1 + sum_{i=1}^{k} (number of d's up to i) (or rearranged). More elegantly: If we let t be the number of increases (i.e., number of d_i = 1), then the sum is k + (something). Actually each increase at position j (meaning d_j=1) will increase a_i for all i>=j by 1. So if there are m increases, and they occur at positions p1, p2, ..., pm (with 2 ≤ p1 < p2 < ... < pm ≤ k), then each increase at p adds 1 to jumps from index p to k. So the contribution beyond the base sum of k (all ones) is sum_{increase at p} (k - p + 1). So total sum = k + Σ (k - p + 1). As we vary the positions of increases, we can achieve different sums. The possible sums range from k (no increases) to k + Σ_{i=1}^{k-1} i = k + (k-1)k/2 = k(k+1)/2 (increases at all possible positions? Actually maximum sum is when we increase at every possible step: d_2=1, d_3=1,..., d_k=1, that gives a_i = i, sum = k(k+1)/2). Now the possible sums are exactly all integers in that range because we can think of representing an integer s - k as a sum of distinct numbers from {1,2,...,k-1} (the contributions of increases), and it's known that every integer from 0 to (k-1)k/2 can be represented as sum of distinct numbers from 1 to k-1? Actually that's the property of binary representation? Not exactly, but the set of subset sums of {1,2,...,k-1} is not all integers up to the total; e.g., for k=4, subset sums of {1,2,3} are 0,1,2,3,1+2=3,1+3=4,2+3=5,1+2+3=6: we get 0,1,2,3,4,5,6. That's all from 0 to 6. For k=5, subsets of {1,2,3,4} sum to all numbers from 0 to 10? Actually maximum sum=10, but can we get 9? Yes, 4+3+2=9, 4+3+1=8, etc. I think the subset sums of a set of consecutive integers from 1 to m are all integers from 0 to m(m+1)/2. This is true because the greedy algorithm can represent any number: since you can take the largest number ≤ remaining, etc. Actually it's known that the set {1,2,...,m} is a complete sequence for subset sums: it can represent every integer from 0 to m(m+1)/2. Proof by induction: For m=1, subset sums: 0,1. Assume for m-1, can represent 0 to (m-1)m/2. Then adding m allows representing m to m + (m-1)m/2 = m(m+1)/2, and also the lower ones are already represented. So yes, it's true. So for start=1, the possible sums are exactly k + S where S is any subset sum of {1,2,...,k-1}, so all integers from k to k + (k-1)k/2 = k(k+1)/2. So indeed all integers in that range are achievable. Great! So rigorous.
For start=2, we can transform similarly: Let a1=2, and for i>=2, a_i = a_{i-1} + d_i with d_i ∈ {0,1}. Then a_i = 2 + Σ_{j=2}^{i} d_j. Total sum = Σ a_i = 2k + Σ_{i=1}^{k} (number of d's up to i) = 2k + Σ_{increase at p} (k - p + 1). The contributions from increases are the same as before: each increase at position p (2 ≤ p ≤ k) adds (k - p + 1) to the total. So total sum = 2k + S, where S is a subset sum of {1,2,...,k-1} (same as before). So the achievable sums are exactly from 2k (no increases) to 2k + (k-1)k/2 = (4k + k(k-1))/2? Let's compute: 2k + (k-1)k/2 = (4k + k(k-1))/2 = (k^2 - k + 4k)/2 = (k^2 + 3k)/2 = k(k+3)/2. And because S can be any integer from 0 to (k-1)k/2, the sums are all integers from 2k to k(k+3)/2. So indeed continuous. So our intervals are exact.
Thus the condition is both necessary and sufficient.
Therefore our algorithm is correct.
Now we can implement.
But we need to output for each test case.
Now there is also possibility that n is huge (like 10^5). Our loop from 1 up to maybe 500 works.
We can also compute directly: find the smallest k such that either n <= k(k+1)/2 and n>=k, or n <= k(k+3)/2 and n>=2k. But since as k increases, the lower bound increases, but the condition might be satisfied earlier for some k then later not? Actually both lower bounds increase with k, so if for some k, n >= k, then for larger k, n might become < k? No, n is fixed, k increases, so eventually k > n, so n >= k becomes false. But the condition also requires n <= max. So there is a range of k where both hold. Typically, for start=1, the condition holds for all k from some minimal k1 up to n? Actually if n is fixed, for start=1, we need k <= n and also n <= k(k+1)/2. The function f(k)=k(k+1)/2 is increasing for k>0. So for k large enough, f(k) >= n. But we also need k <= n. So the feasible k for start=1 are those k such that k <= n and f(k) >= n. The smallest such k is when f(k) first becomes >= n while also k <= n. Since f(k) is increasing, we can find the smallest k such that f(k) >= n. If that k <= n, then it's feasible. Usually the k that satisfies f(k) >= n is around sqrt(2n) which is much less than n for n>2. So it will satisfy k <= n automatically. So the condition for start=1 reduces essentially to k >= ceil( (sqrt(8n+1)-1)/2 ). But still need to ensure n >= k? That might be automatically true for that k? For n=1, k=1, ok. For n=2, f(2)=3 >=2, but k=2, does k <= n? 2<=2, yes, so condition holds for k=2? But we found k=2 start=1 gives min=2 max=3, includes 2? Actually start=1 with k=2 sum can be 2 (1+1) or 3. So yes, 2 is reachable in 2 jumps via start=1? Wait earlier we said for n=2, answer is 1. But is it possible to reach in 2 jumps with start=1? Yes: 1+1=2. So k=2 is also a solution, but not minimal. So start=1 condition yields k=2 as feasible, but we want minimal. So minimal is 1 via start=2. So we need to consider both starts.
Thus we can compute candidate k from both starts and take minimum. For start=1, the minimal feasible k1 is the smallest integer k such that k(k+1)/2 >= n (and automatically n >= k because for k such that k(k+1)/2 >= n, if k > n, could that happen? For n small? For n=1, k=1 <=1; for n=2, k=2 <=2; for n=3, k=2 <=3; for n=4, k=3? f(3)=6 >=4, and k=3 <=4, ok; for n=5, k=3 <=5; for n=100, k=14 <=100; for n=100000, k=447 <=100000. So k always <= n? Check: Suppose n=100000, k=447, yes. Could there be n where smallest k with f(k)>=n is greater than n? That would require f(n) < n, i.e., n(n+1)/2 < n => n(n+1) < 2n => n+1 < 2 => n<1, impossible for n>=1. So indeed for any n>=1, f(n) = n(n+1)/2 >= n. So the smallest k with f(k)>=n is at most n. Actually it's less than or equal to n because f(n) >= n. So k1 <= n. So condition n >= k holds automatically for that minimal k1 (and for any k between k1 and n, it also holds). So for start=1, the minimal feasible k is k1 = ceil( (sqrt(8n+1)-1)/2 ). That yields smallest k such that f(k) >= n.
Similarly, for start=2, the condition is n <= k(k+3)/2 and also n >= 2k. The function g(k)=k(k+3)/2 is increasing. The smallest k such that g(k) >= n is, say, k2 = ceil( (sqrt(8n+9)-3)/2 )? Solve k^2+3k-2n >=0 => k = ceil( (-3 + sqrt(9+8n))/2 ). But also need n >= 2k. Is that automatically satisfied for that k2? Not necessarily. For n small, e.g., n=4, g(2)=5 >=4, k2=2, and n=4 >= 2*2=4, ok. For n=3, g(2)=5 >=3, k2=2, but n=3 >= 4? 3 >=4 false, so condition fails. But for start=2, we also need n >= 2k. So the feasible k must satisfy both: k <= floor(n/2) and g(k) >= n. The minimal feasible k2 would be the smallest k satisfying both. Typically, g(k) >= n might hold for some k that is larger than floor(n/2), but then the condition n >= 2k fails. Actually if k > n/2, then 2k > n, so condition fails. So we need k <= floor(n/2). So for start=2, feasible k exist only if there is k <= n/2 such that g(k) >= n. But note that g(k) grows quadratically, so for large n, the smallest k satisfying g(k) >= n might be about sqrt(2n), which is much less than n/2 for n large (since sqrt(2n) < n/2 for n > 8). So it's okay. For small n, we need to check.
Thus we can compute two candidates:
- k1 = ceil( (sqrt(8n+1)-1)/2 )
- k2 = smallest integer k such that g(k) >= n and k <= n/2. Actually we could compute k2cand = ceil( (sqrt(8n+9)-3)/2 ), but then need to ensure k2cand <= n/2; if not, then maybe no k2? But there might be a larger k? Actually if k2cand > n/2, then for any k >= k2cand, we have k > n/2, so n >= 2k fails. For k smaller than k2cand, g(k) < n. So no k satisfies both. So start=2 not feasible for those n. For example, n=3, k2cand = ceil( (sqrt(24+9? Actually 83+9=33, sqrt~5.744, -3=2.744, /2=1.372 => ceil=2) k2cand=2, but 2 > 3/2=1.5? Actually n/2=1.5, k2cand=2 > 1.5, so no k satisfies both. Indeed start=2 not feasible for n=3. For n=2, k2cand = ceil( (sqrt(16+9? Actually 82+9=25, sqrt=5, -3=2, /2=1) -> 1? Compute: sqrt(25)=5, -3=2, /2=1 => exactly 1, so k2cand=1, and 1 <= n/2=1, so feasible. Good. For n=1, k2cand = ceil( (sqrt(8+9=17)~4.123-3=1.123/2=0.561 => ceil=1), but 1 <= 0.5? n/2=0.5, 1 >0.5, so not feasible. Indeed start=2 cannot reach 1. So that matches.
Thus we can compute two candidates and take min of the feasible ones. However, we need to also consider that for start=1, the minimal k1 might not be feasible if n < k1? But we argued it's always. So k1 is always feasible. For start=2, candidate k2 = the smallest integer k such that k(k+3)/2 >= n and k <= n/2. That's the minimal feasible k for start=2. If such k exists, then answer is min(k1, k2). If not, answer = k1.
We can compute k2 by iterating k from 1 to maybe floor(n/2) but that could be up to 50000 for n=100k, not ideal if we do for each test? But we can compute via formula: k2cand = ceil( ( -3 + sqrt(9+8n) ) / 2 ). Then check if k2cand <= n/2. If yes, then k2 = k2cand is the minimal? Because g(k) is increasing, so the smallest k with g(k) >= n is k2cand. If that satisfies k2cand <= n/2, then it's feasible. But what if k2cand > n/2, but there exists some k < k2cand that satisfies g(k) >= n? No, because k2cand is the smallest with g(k) >= n. So if k2cand > n/2, then no k satisfies both. So start=2 infeasible.
But wait: Could there be a case where k2cand > n/2, but a larger k? Actually larger k > k2cand also > n/2, so fails n >= 2k. So indeed no feasible start=2.
Thus we can compute k2 = k2cand if k2cand <= n/2, else start=2 infeasible.
Now we also need to consider that for start=1, the minimal k1 may be less than k2 or vice versa. So answer = min(k1, k2) if k2 exists else k1.
But careful: Could there be a scenario where the minimal k for start=1 is not exactly k1? Because maybe for that k1, n is less than k1? Not possible. So fine.
Now we must also consider that for start=1, the condition also requires that n is at least k1. Since k1 is derived from f(k) >= n, and for k1, is it guaranteed that n >= k1? As argued, f(k1) >= n, but could k1 > n? Suppose n=2, k1=2, 2 >=2 true. For n=1, k1=1. So it's fine.
Thus we can compute answer analytically with O(1) per test. But loop up to 500 is also fine; however, to be safe and simpler, we can just loop.
Given constraints, loop is acceptable. However, if we want to be fancy, we could implement formula. But either is okay.
But note: The problem constraints: t up to 100, n up to 10^5, loop up to maybe 447 per test is 44700 operations, trivial. So we can keep it simple.
But we need to be careful about integer multiplication overflow? In Python it's fine. In C++ using int, k up to 447, product ~200k, fine.
Thus I'll implement a loop.
But wait: The loop condition: while True: we break when either condition holds. Starting from k=1. For n=100000, we will loop up to 446 maybe. That's fine.
Now let's test some values manually with loop to be sure:
n=1: k=1: first condition: 1 <=1 and 1<=1 => true, output 1.
n=2: k=1: first? 1<=2 and 2<=1? false; second: 2<=2 and 2<=2 => true, output 1.
n=3: k=1: first? 1<=3 and 3<=1? false; second: 2<=3 and 3<=2? false. k=2: first: 2<=3 and 3<=3? true, output 2.
n=4: k=1: first? false; second: 2<=4 and 4<=2? false. k=2: first: 2<=4 and 4<=3? false; second: 4<=4 and 4<=5? true, output 2.
n=5: k=2: first false; second: 4<=5 and 5<=5 true, output 2.
n=6: k=2: first? 2<=6 and 6<=3? false; second: 4<=6 and 6<=5? false. k=3: first: 3<=6 and 6<=6 true, output 3.
n=7: k=3: first: 3<=7 and 7<=6? false; second: 6<=7 and 7<=9 true, output 3.
n=8: k=3: first false; second: 6<=8 and 8<=9 true, output 3.
n=9: k=3: first false; second: 6<=9 and 9<=9 true, output 3.
n=10: k=3: first? 3<=10 and 10<=6? false; second: 6<=10 and 10<=9? false. k=4: first: 4<=10 and 10<=10 true, output 4.
Works.
Now I should double-check for n=11: k=4: first: 4<=11 and 11<=10 false; second: 8<=11 and 11<=14 true, output 4.
n=12: k=4: first false; second: 8<=12 and 12<=14 true, output 4.
n=13: k=4: second: 8<=13 and 13<=14 true, output 4.
n=14: k=4: second: 8<=14 and 14<=14 true, output 4.
n=15: k=4: first false; second: 8<=15 and 15<=14 false. k=5: first: 5<=15 and 15<=15 true, output 5.
Seems consistent.
Now edge: n=44700? Let's compute approximate. But loop is fine.
Thus solution: for each n, find smallest k satisfying either condition.
Now is there any scenario where a k smaller than the one found by this loop exists but we missed because both conditions check for n <= max but also n >= min, but perhaps for start=1, the min is not exactly k? Wait: For start=1, min is k because smallest possible sum with k jumps is 1+1+...+1 = k. So n must be at least k. That's correct.
Similarly for start=2, min is 2k.
Thus loop is correct.
Now let's think about a possible alternative: Could starting with 2 but then later we could possibly have a jump less than 2? No, because we can only stay or increase, never decrease. So min for start=2 is indeed 2k.
Thus answer.
Now we can implement.
Now let's also consider if there is any possibility that a sequence with k jumps could have sum less than k? No, because each jump at least 1. So fine.
Thus I'll code.
I'll produce Python solution:
def min_jumps(n):
k = 1
while True:
if k <= n and n <= k*(k+1)//2:
return k
if 2k <= n and n <= k(k+3)//2:
return k
k += 1
But note: For large n, the loop will go up to ~447. For n=100000, it will break at k=446? Actually check: For k=446, compute max_start2 = 446449//2 = let's compute: 446449 = 446400=178400, 44649=21854, sum=200254, //2=100127. So n=100000 <=100127, and 2k=892 <=100000, so condition true. So it returns 446. That is minimal? Could k=445 satisfy? k=445: max_start2 = 445448//2 = 445224 = 99680, less than 100000, so false; max_start1 = 445446//2 = 445223 = 99235? Actually 445*446=198470, /2=99235, less than 100000; so false. So indeed 446. So loop stops at 446.
Now note: For n=100000, start=1 condition at k=447 would also be true (since max_start1=100128, min=447 <=100000), but 447 > 446, so we return 446. So minimal.
Thus correct.
Now we need to handle t up to 100, we can just loop for each test.
Now before finalizing, consider if any n leads to loop up to n (e.g., n=1? no). For n=2, loop stops at 1. For n=3 stops at 2. So always small.
Thus solution done.
But I'll also think about the possibility of n=0? Not allowed.
Now we can produce final answer.
However, the problem statement says "0<n ≤ 10^5". So all positive.
Now let's write code accordingly.
But note: The input sample:
2
2
3
Output:
1
2
Matches.
Now I'll produce final solution.
Potential pitfalls: integer division rounding? In Python // is floor division, but we have exact integers, product even/odd? k(k+1) is always even? Actually product of two consecutive integers is even, so division yields integer. Similarly, k(k+3): If k is odd, k+3 is even? Not necessarily: e.g., k=2 => 25=10 even; k=3 => 36=18 even; k=4 =>47=28 even; k=1 =>14=4 even. So k(k+3) always even? Check parity: If k is even, product even; if k is odd, k odd, k+3 even (since odd+odd? Actually odd+3 = even? 1+3=4 even, 3+3=6 even, 5+3=8 even), so product even. So integer division safe.
Thus we can compute directly.
Now to be thorough, we can also implement a precomputed array of maximums for each k and then binary search, but not needed.
Thus final answer.
I'll write the solution in a clear manner.
One more thought: Could the initial step be taken as 1 or 2, but also maybe the first step could be considered a "jump"? Yes.
Now I think it's correct.
But let's verify some more random numbers with a brute force program? Not necessary but let's manually test n=16.
k=5: start1 max=15 <16; start2 max=20 includes 16, min=10, so k=5 works? Check sequence: maybe 2+3+3+4+4=16? 2+3=5, +3=8, +4=12, +4=16 => 2,3,3,4,4 works? a1=2, a2=3 (inc), a3=3 (stay), a4=4 (inc), a5=4 (stay) -> sum=16. So 5 jumps. k=4? max start2=14 <16, so no. So answer 5.
n=17: k=5: start2 max=20 includes 17, min=10, so 5 jumps possible: 2+3+4+4+4=17? 2+3=5, +4=9, +4=13, +4=17 => sequence 2,3,4,4,4 works? a1=2, a2=3, a3=4, a4=4 (stay), a5=4 (stay). Allowed. So answer 5.
n=18: k=5: 2+3+4+4+5=18? 2+3=5, +4=9, +4=13, +5=18: after 4 can go to 5 => allowed. So 5 jumps. Good.
n=19: k=5: 2+3+4+5+5=19? 2+3+4+5+5=19, sequence: 2,3,4,5,5 allowed? from 4 to 5 (inc), from 5 to 5 (stay) -> sum=14? Actually compute: 2+3=5, +4=9, +5=14, +5=19. Wait 14+5=19, yes. So 5 jumps.
n=20: k=5, max=20, so (2,3,4,5,6) sum=20. So 5 jumps.
Thus for n=16-20, answer 5.
Now n=21: we found k=6 from start1. So seems consistent.
Thus algorithm works.
Now just to be safe, let's test n=44700 with approximate: k for start2? compute k(k+3)/2 >=44700. Solve k^2+3k-89400=0 => discriminant = 9+357600=357609, sqrt≈598.0? Actually sqrt(357609) = 598.0? Let's compute: 598^2=357604, 599^2=358801, so sqrt≈598.0? 598^2=357604, so discriminant=9+4*44700? Wait, we have 8n? Actually g(k)=k(k+3)/2, so inequality k(k+3) >= 89400 => k^2+3k-89400>=0. Discriminant = 9+357600=357609, sqrt≈598.005? Actually 598^2=357604, 598.005^2 ≈357609? So k = (-3+598)/2=595/2=297.5, so ceil =298. So k=298 approx. Then check if 2k=596 <=44700, yes. So answer would be min(k1, k2). k1 for start1: f(k)=k(k+1)/2 >=44700 => k^2+k-89400>=0, discriminant=1+357600=357601, sqrt≈598.0? 598^2=357604, actually 598^2=357604, 597^2=356409, so sqrt≈598.0? Compute: (sqrt(357601)≈598.0) Actually 598^2=357604 >357601, so sqrt≈597.999? So k = (-1+598)/2=597/2=298.5, ceil=299. So k1=299. So k2=298 is smaller, answer 298. So loop would find k=298. Good.
Now note: For some n, the minimal k might be from start=1, even if start=2 is feasible, because k1 < k2. Example n=10, k1=4, k2? For start=2: solve g(k)>=10 => k^2+3k-20>=0 => discriminant=9+80=89, sqrt≈9.433, k=(-3+9.433)/2=6.433/2=3.216, ceil=4. So k2cand=4, and 2k=8 <=10, so k2=4. Both equal. n=6: k1=3, k2? g(k)>=6 => k^2+3k-12>=0 => disc=9+48=57 sqrt≈7.55, k=(-3+7.55)/2=4.55/2=2.275, ceil=3, 2k=6 <=6, so k2=3. Equal. n=7: k1=4? Actually for n=7, f(k)>=7: solve k(k+1)/2>=7 => k^2+k-14>=0 => disc=1+56=57, sqrt≈7.55, k=(-1+7.55)/2=6.55/2=3.275, ceil=4 => k1=4. But we found answer 3 via start=2. Let's compute k2: g(k)>=7 => k^2+3k-14>=0 => disc=9+56=65 sqrt≈8.062, k=(-3+8.062)/2=5.062/2=2.531, ceil=3, 2k=6 <=7 => k2=3. So k2=3 < k1=4. So answer is 3. So start=2 gave smaller.
Thus our loop will find k=3 because at k=3 second condition holds. So correct.
Now let's test n=1e5: k1 approx ceil((sqrt(800001)-1)/2). sqrt(800001) ≈ 894.43? Actually sqrt(8100000+1)=sqrt(800001) ≈ 894.427 (since 894.427^2≈800,000). So (894.427-1)/2=893.427/2=446.7135, ceil=447. So k1=447. k2: sqrt(8100000+9)=sqrt(800009)≈894.434? Actually same approx; (-3+894.434)/2=891.434/2=445.717, ceil=446. So k2=446, and 2k=892 <=100000, so answer 446. So loop returns 446.
Thus all good.
Now edge: n=2? k2=1 as earlier, k1=2? Actually f(k)>=2 => k(k+1)/2>=2 => k^2+k-4>=0 => disc=1+16=17 sqrt≈4.123, k=(-1+4.123)/2=3.123/2=1.5615 ceil=2 => k1=2. So min(2,1)=1. Good.
Now n=3: k1=2, k2? g(k)>=3 => k^2+3k-6>=0 => disc=9+24=33 sqrt≈5.7446, k=(-3+5.7446)/2=2.7446/2=1.3723 ceil=2, but 2k=4 >3, so k2 not feasible. So answer=2.
Thus min works.
Now note: For n=4, k1? f(k)>=4 => k^2+k-8>=0 => disc=1+32=33 sqrt≈5.7446, k=(-1+5.7446)/2=4.7446/2=2.3723 ceil=3 => k1=3. k2? g(k)>=4 => k^2+3k-8>=0 => disc=9+32=41 sqrt≈6.4031, k=(-3+6.4031)/2=3.4031/2=1.7016 ceil=2, and 2k=4 <=4, so k2=2. So min=2. Answer=2. Loop gives 2.
Now for n=5, k1: f(k)>=5 => k^2+k-10>=0 => disc=1+40=41 sqrt≈6.4031, k=(-1+6.4031)/2=5.4031/2=2.7016 ceil=3 => k1=3. k2: g(k)>=5 => k^2+3k-10>=0 => disc=9+40=49 sqrt=7, k=(-3+7)/2=4/2=2, ceil=2? Actually exact: k=2 gives g(2)=5, so k2cand=2, and 2k=4 <=5, so k2=2. min=2. Answer 2.
Now for n=6, k1: f(k)>=6 => k^2+k-12>=0 => disc=1+48=49 sqrt=7, k=(-1+7)/2=6/2=3, ceil=3 => k1=3. k2: g(k)>=6 => k^2+3k-12>=0 => disc=9+48=57 sqrt≈7.55, k=(-3+7.55)/2=4.55/2=2.275 ceil=3, and 2k=6 <=6, so k2=3. min=3. Answer 3.
So formula works.
Thus loop is okay, but if we wanted O(1) we could compute both candidates. However, the loop is simpler to ensure correctness and avoid off-by-one.
Now we need to be careful about the while True loop: it will eventually terminate because for k = n, start=1 condition holds (since n <= n(n+1)/2). So it's safe.
Now we can write final code.
But we need to consider that for large t, the loop per test might be slightly inefficient but fine.
Now let's implement in Python:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data:
return
t = int(data[0])
out = []
idx = 1
for _ in range(t):
n = int(data[idx]); idx+=1
k = 1
while True:
if k <= n and n <= k*(k+1)//2:
out.append(str(k))
break
if 2k <= n and n <= k(k+3)//2:
out.append(str(k))
break
k += 1
sys.stdout.write("\n".join(out))
But we should ensure that the loop does not become infinite if we mis-handle n=0; but n>0.
Now test with sample:
t=2, n=2, n=3.
For n=2: k=1: first? 1<=2 true, n<=1? false. second: 2<=2 true, n<=2? true -> output 1.
For n=3: k=1: first false, second false. k=2: first: 2<=3 true, n<=3 true -> output 2.
Matches.
Now we might think about an optimization: we could compute the minimal k directly using integer sqrt. But fine.
Now let's double-check for n=44700 we had k2=298. Our loop would start from k=1 and go to 298. That's 298 iterations, fine.
Now n=100000 -> 446 iterations, fine.
Now t=100 -> total up to 44,600 iterations, trivial.
Thus solution accepted.
Now I'd like to also think about potential pitfalls: The problem states "0<t ≤ 100" and "0<n ≤ 10^5". So all positive.
Thus final answer.
But before finalizing, let's test extreme cases:
n=1: output 1.
n=100000: output 446? Let's compute manually to be sure:
k=446: start2 condition: 2446=892 <=100000, max=446449/2= (446449)/2. 446449= 446*450 - 446 = 200700 - 446 = 200254, /2=100127 >=100000, so condition true. So answer 446.
Now could there be k=445 that works? max start2=445448/2= (445448)=445400=178000, 44548=21360, total=199360, /2=99680 <100000, so not. start1 max=445446/2= (445446)=445400=178000, 44546=20470, total=198470, /2=99235 <100000. So no. So 446 is minimal.
Thus answer.
Now let's consider n=99999: k=446? max start2=100127 >=99999, min=892 <=99999, so works. Could k=445? max start2=99680 <99999, so no. So answer 446. So for many n near 100k, answer 446.
But if n=100128, that's > 100127, so start2 fails at k=446, so need k=447: start1 max=100128, min=447, n=100128 >=447? yes, 100128 <= 100128, so works. So answer 447. So max answer for n=100000 range is 447.
Thus loop works.
Now I'll produce final answer.
But wait: The problem says "Initially he can take 1 or 2 steps. If he jumps x steps at a time then in the next step he can climb either x or x+1 steps depending on his choice and he must reach exactly on n'th step." It might be interpreted as: At each step, the jump length can be either the same as previous or increased by 1, starting from initial choice 1 or 2. So we covered that.
Now I want to confirm that after a jump of x, the next step can be either x or x+1, meaning it cannot be less than x. So it's non-decreasing. That's what we used. So min sums are as we computed.
Now one might ask: Could the initial step be considered as a jump? Yes.
Now everything fine.
Thus final solution is as above.
We'll output minimum number of jumps.
I'll now craft final answer with explanation.
But as ChatGPT, I need to produce a final answer that includes code and reasoning.
Given the instruction: "We need to produce the final answer." I'll provide a solution in Python.
But the problem might be from a coding platform expecting C++? Usually these problems accept multiple languages. I'll write in Python for simplicity.
Thus final.
But let me also consider if there is any nuance about the input: The first line t, then t lines each with n. Could there be extra spaces? We'll handle with split.
Now finalize.
I'll also add a comment for clarity.
Now I think it's done.
Before final, I'll test some more cases manually with a small script mentally:
n=25: compute k1: f(k)>=25 => k(k+1)/2>=25 => approx k=7? 78/2=28 >=25, so k1=7? Actually check k=6:67/2=21<25, so k1=7. k2: g(k)>=25 => k(k+3)/2>=25. For k=6:69/2=27 >=25, 2k=12 <=25, so k2=6? Let's check k=5:58/2=20 <25, so k2=6. So answer min(7,6)=6. So answer 6. Check: 6 jumps start=2: can we sum to 25? max=27, min=12, so likely possible. For instance, 2+3+4+5+6+5=25? 2+3=5, +4=9, +5=14, +6=20, +5=25. But after 6, can we do 5? No, cannot decrease. So that sequence invalid. Try 2+3+4+5+5+6=25? Sum: 2+3=5, +4=9, +5=14, +5=19, +6=25. Check: a1=2, a2=3, a3=4, a4=5, a5=5 (stay), a6 from 5 can be 5 or 6 -> choose 6 => allowed. So sum=2+3+4+5+5+6=25, allowed. So yes 6 jumps. Good.
n=26: k1=7? f(7)=28>=26, k1=7; k2=6? g(6)=27>=26, 2k=12<=26, so k2=6 works? Need to check if 26 achievable with 6 jumps start=2. max=27, min=12, so should be. For instance, 2+3+4+5+6+6=26? 2+3+4+5+6+6=26, allowed: a1=2, a2=3, a3=4, a4=5, a5=6 (from 5 to 6), a6 from 6 can be 6 (stay). So sum=2+3+4+5+6+6=26, yes. So answer 6. So for n up to 27 maybe answer 6. n=27: k2=6 gives max=27, so 6 jumps. n=28: k2=6 max=27 <28, so k2 not; k1=7 gives max=28, so answer 7. So interesting: 27 is reachable in 6, 28 requires 7.
Now check n=28 with start=1: 1+2+3+4+5+6+7=28, 7 jumps. So answer 7.
Thus pattern.
Now I'm convinced.
Now I'll produce final answer.
One more thing: Should we consider that Joy might be able to make 0 jumps? No, he must reach exactly nth step, and initially he is at ground (step 0). So at least one jump.
Thus done.
Now final answer in Python.
But the user might expect code in C++? The problem didn't specify. I'll write Python.
I'll include fast I/O for safety.
Alright.
Now produce final answer. ```python
import sys
def min_jumps(n: int) -> int:
k = 1
while True:
# start with 1 step
if k <= n and n <= k * (k + 1) // 2:
return k
# start with 2 steps
if 2 * k <= n and n <= k * (k + 3) // 2:
return k
k += 1
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
t = int(data[0])
out = []
idx = 1
for _ in range(t):
n = int(data[idx])
idx += 1
out.append(str(min_jumps(n)))
sys.stdout.write("\n".join(out))
if name == "main":
solve()