1782: Just A Few More Triangle!

内存限制:128 MB 时间限制:10.000 S
评测方式:文本比较 命题人:
提交:0 解决:0

题目描述

Simon Haples is a somewhat peculiar person. Not quite hip, not quite square, he is more of a triangular nature: ever since childhood, he has had an almost unhealthy obsession with triangles. Because of his discrete nature, Simon‘s favorite kind of triangles are the Pythagorean ones, in which the side lengths are three positive integers a, b, and c such that a ≤ b and a2 + b2 = c2. Recently, Simon has discovered the fantastic world of counting modulo some integer n. As you may imagine, he quickly realizes that there are multitudes of Pythagorean triples to which he has previously been oblivious! Simon therefore sets out to find all Pythagorean triples modulo n, i.e., all triples of integers a, b and c between 1 and n - 1 such that a ≤ b and a2 + b2 ≡ c2 (mod n).

输入

The input consists of a single integer n, satisfying 2 ≤ n ≤ 500 000.

输出

Output the number of Pythagorean triples modulo n.

样例输入 复制

case1:
7

case2:
15

样例输出 复制

case1:
18

case2:
64

来源/分类