#P1646C. Factorials and Powers of Two
Factorials and Powers of Two
No submission language available for this problem.
Description
A number is called powerful if it is a power of two or a factorial. In other words, the number is powerful if there exists a non-negative integer such that or , where (in particular, ). For example , , and are powerful numbers, because , , and but , , or are not.
You are given a positive integer . Find the minimum number such that can be represented as the sum of distinct powerful numbers, or say that there is no such .
Each test contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
A test case consists of only one line, containing one integer ().
For each test case print the answer on a separate line.
If can not be represented as the sum of distinct powerful numbers, print .
Otherwise, print a single positive integer — the minimum possible value of .
Input
Each test contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
A test case consists of only one line, containing one integer ().
Output
For each test case print the answer on a separate line.
If can not be represented as the sum of distinct powerful numbers, print .
Otherwise, print a single positive integer — the minimum possible value of .
Samples
Note
In the first test case, can be represented as , where and are powerful numbers. Because is not a powerful number, we know that the minimum possible value of in this case is .
In the second test case, a possible way to represent as the sum of three powerful numbers is . We can show that there is no way to represent as the sum of two or less powerful numbers.
In the third test case, can be represented as . Observe that is not a valid representation, because the powerful numbers have to be distinct.
In the fourth test case, , so is a powerful number and the minimum in this case is .