atcoder#ABC293F. [ABC293F] Zero or One

[ABC293F] Zero or One

Score : 500500 points

Problem Statement

Given an integer NN not less than 22, find the number of integers bb not less than 22 such that:

  • when NN is written in base bb, every digit is 00 or 11.

Find the answer for TT independent test cases.

It can be proved that there is a finite number of desired integers bb not less than 22 under the constraints of this problem.

Constraints

  • 1T10001 \leq T \leq 1000
  • 2N10182 \leq N \leq 10^{18}
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format, where testi\mathrm{test}_i denotes the ii-th test case:

TT

test1\mathrm{test}_1

test2\mathrm{test}_2

\vdots

testT\mathrm{test}_T

Each test case is given in the following format:

NN

Output

Print TT lines. For i=1,2,,Ti = 1, 2, \ldots, T, the ii-th line should contain the answer to the ii-th test case.

3
12
2
36
4
1
5

For the first test case, four bb's satisfy the condition in the problem statement: b=2,3,11,12b = 2, 3, 11, 12. Indeed, when N=12N=12 is written in base 2,3,112, 3, 11, and 1212, it becomes 1100,110,111100, 110, 11 and 1010, respectively.