You are given an integer N. We call a string S good if it satisfies the following conditions:
- \(S[i] = a \text{ or } S[i] = b \text{ } \forall \text{ } 1 \leq i \leq len(S)\)
- \(S[i] \leq S[i + 1] \text{ } \forall \text{ } 1\leq i \leq len(S) - 1\). Recall that \(a < b\) according to the numbering of ASCII table.
Here \(len(S)\) denotes the length of string $$S$$. For example, the strings "\(aabb\)", "\(abb\)", "\(aaa\)", "\(bbb\)", "\(a\)" are good but strings "\(aba\)", "\(bab\)", "\(bba\)" are not.
Your task is to find the minimum length of a good string which has atleast N distinct substrings.
Notes
- A substring of a string is a contiguous subsequence of that string. For example, "hacker" is subtring of "hackerearth", but "hackr" is not.
- Two substrings \(X\) and \(Y\) are different if:
- They are of different length.
- If they are of the same length, then there is an index \(i \) such that \(X[i] \neq Y[i]\).
Input
- The first line contains a single integer T denoting the number of test cases.
- For each test case, the only line of input contains a single integer N.
Output
For each test case (in a separate line), output the minimum length of a good string which has at least N distinct substrings.
Constraints
\(1 ≤ T ≤ 5000 \\ 1 ≤ N ≤ 10^9\)
In the first test case, we have $$N = 5$$, possible good strings are "$$abb$$", "$$aab$$". For example, distinct substrings of "$$abb$$" are "$$a$$", "$$ab$$", "$$abb$$", "$$b$$", "$$bb$$". It can be proved that no good string of length less than 3 has at least 5 distinct substrings.
In the second test case, we have $$N = 8$$, possible good string is "$$aabb$$". For example, distinct substrings of "$$aabb$$" are "$$a$$", "$$aa$$", "$$aab$$", "$$aabb$$", "$$ab$$", "$$abb$$", "$$b$$", "$$bb$$". It can be proved that no good string of length less than 4 has at least 8 distinct substrings.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor