Hide

Problem D
All Modulo Pythagorean

Languages en is

You are given a value n and should investigate Pythagorean triples modulo n. This means we are considering triples (a,b,c) where 0<a,b,c<n that satisfy a2+b2=c2(modn) and ab.

For example in the first sample the solutions are (1,2,1), (1,2,3), (2,2,2), (2,3,1) and (2,3,3).

Input

The first and only line of input contains a positive integer n, the modulo we are considering. It will satisfy 1n2105.

Output

Print the number of Pythagorean triples modulo n.

Sample Input 1 Sample Output 1
4
5
Sample Input 2 Sample Output 2
7
18
Sample Input 3 Sample Output 3
15
64
Hide

Please log in to submit a solution to this problem

Log in