Under construction

Still being built. Things may change

Junk or Joy

Time limit2sMemory limit512 MB

Summary
Given k, count tuples (n, p, m) of positive integers with p prime and n^2 - k*p^m = 1, or print -1 if there are infinitely many.
Level

Medium7 of 10

Topics
Math, Number theory
Solved
No attempts yet

Statement

You are given a positive integer kk. Count the tuples of positive integers (n,p,m)(n, p, m) such that n2−k⋅pm=1n^2 - k \cdot p^m = 1 and pp is a prime number. If there are infinitely many such tuples, print −1-1.

Input

The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). Each test case is described by a single line containing one integer kk (1≤k≤1091 \le k \le 10^9).

Output

For each test case, print the number of positive integer tuples (n,p,m)(n, p, m) satisfying n2−k⋅pm=1n^2 - k \cdot p^m = 1 with pp prime, or −1-1 if there are infinitely many of them.

Hint

In the first test case, for k=5k = 5, the only possible tuples are (4,3,1)(4, 3, 1), (6,7,1)(6, 7, 1), and (9,2,4)(9, 2, 4). In the second test case, for k=22k = 22, no tuples exist.

Examples1

  1. Example 1

    Input
    2
    5
    22
    
    Expected output
    3
    0