#P9814. SPY finding NPY

SPY finding NPY

SPY finding NPY

Problem Description

Recently, SPY has retired from XCPC. He cherishes the memory of learning algorithms from scratch and winning the ICPC gold medal. So he is finding an NPY (non-programming youth) to be his successor. SPY is so popular that nn NPYs want to be his apprentice. As SPY only needs one NPY, he sets a test for the nn NPYs. The rules are as follows: nn NPYs are indexed from 11 to nn. SPY will interview the nn NPYs in order. The ii-th NPY will be tested in the ii-th interview. After an NPY is interviewed, SPY will get her IQ (intelligence quotient) number (an integer in [0,202320232023][0,2023^{2023^{2023}}]) . SPY can decide whether to accept her or not. Once he accepts an NPY, the test would be finished and he won't interview the following NPYs. Once he refuses an NPY, he won't give her another chance. Notice that there are no two NPYs with the same IQ. SPY has a specital strategy to find an NPY with high IQ. He sets an integer kk (0k<n)(0\leq k < n) before the test. 1、No matter how intelligent the first kk NPYs are, they will be refused. SPY will record the highest IQ number xx within the first kk NPYs. If k=0k=0 then x=1x=-1. 2、Then he will interview the (k+1)(k+1)-th to the (n1)(n-1)-th NPY. Once SPY interviews an NPY with IQ higher than xx, he will accept her and finish the test. 3、If no NPY is accepted, SPY will accept the nn-th NPY. The IQ rank of the nn NPYs is random, which means their rank is a permutation of 1n1\sim n, and the n!n! possible situations occur with equal probability. Althouth SPY is a master of useful algorithms, it is difficult for him to set the number kk. Can you help him to calculate the minimum kk to maximize the probability to accept the NPY with the highest IQ?

Input

The first line contains a single integer TT (1T104)(1\leq T \leq 10^4), indicating the number of test cases. The next TT lines, each line contains a single integer nn (1n104)(1\leq n \leq 10^4), indicating the number of NPYs.

Output

For each test, you should output one integer in a line, indicating the integer kk.

Sample Input

8
1
2
3
4
9000
9001
9002
9003

Sample Output

0
0
1
1
3311
3311
3311
3312

Hint

In the third test, there are 33 NPYs. Let the array pp represent to the IQ rank. The IQ rank of ii-th NPY is pip_i. The uu-th NPY with pu=1p_u=1 has the lowest IQ, and the vv-th NPY with pv=3p_v=3 has the highest IQ. There are 3!=63!=6 situations occur with equal probability. The following list shows the IQ rank of the accepted NPY in all situations, and the probability to accept the NPY with the highest IQ. 图片

Source

2023“钉耙编程”中国大学生算法设计超级联赛(2)