Rikka with Equation
Time limit2sMemory limit512 MB
For each n, count tuples (a, b, m) with m at most n such that some integers x and y satisfy x^2 + y^2 is congruent to a and xy is congruent to b modulo m.
- Level
Hard9 of 10
- Topics
- Math, Number theory
- Solved
- No attempts yet
Problem
The conclusion of Hilbert's tenth problem shows that no algorithm can find all integer solutions of an arbitrary system of equations. However, some simple equations are still easily solvable.
For example, how do we check whether there exist two integers and that satisfy and ? We can compute and , and then check whether both and can be integers.
Rikka thinks this task is too simple, so she wants to make it look harder. Rikka knows that sometimes considering an equation modulo makes the problem different. So she wants to do the same with this problem.
A tuple with is valid if and only if there exist two integers and that satisfy and . Given a positive integer , count the number of valid tuples with . Since this number may be large, output it modulo .
Input
The first line contains a single integer (), the number of test cases. Each test case is given on a separate line containing a single integer ().
Output
For each test case, output a single line containing the number of valid tuples modulo .