Junk or Joy
Time limit2sMemory limit512 MB
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 . Count the tuples of positive integers such that and is a prime number. If there are infinitely many such tuples, print .
Input
The first line contains the number of test cases (). Each test case is described by a single line containing one integer ().
Output
For each test case, print the number of positive integer tuples satisfying with prime, or if there are infinitely many of them.
Hint
In the first test case, for , the only possible tuples are , , and . In the second test case, for , no tuples exist.