#P107. [Sleeping Cup #4] Factorial Master
[Sleeping Cup #4] Factorial Master
Person in Charge
Attention
is the hard version of this problem.
This problem requires file I/O (factorial.in / factorial.out).
Problem Background
The lottery results are out. Sleeping Dolphin was surprised to find that he didn't win because... he accidentally bought a different lottery ticket.
Sleeping Dolphin checked his phone—it was already 1:00 AM on April 13th.
Time to focus on setting problems for Sleeping Cup. Let's get to work.
Problem Description
Find the maximum positive integer solution to the following equation:
where .
If no such positive integer solution exists, output .
Input Format
There are multiple test cases.
The first line contains a positive integer indicating the number of test cases.
Each of the next lines contains a positive integer .
Output Format
Output lines, each containing a non-negative integer representing the answer.
Samples
5
1
2
3
4
5
0
1
1
1
3
5
118
119
120
121
122
1
5
1
9
1
Sample 1 Explanation
From the red-marked parts in the table above, the answers for the sample are .
Note that when , the equation has infinitely many positive integer solutions (), so the answer is .