The Pythagorean Theorem
Time limit1sMemory limit128 MB
Given n, count ordered triples (a,b,c) with 1<=a<=b<=n-1 and c<=n-1 such that a^2+b^2 is congruent to c^2 modulo n.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
Sanggeun loves triangles, and right triangles most of all.
A right triangle has side lengths that are positive integers , , with and .
After learning modular arithmetic, Sanggeun decided to apply it to the Pythagorean theorem.
Given an integer , he wants to count the ordered triples with and that satisfy
Write a program that, given , computes the number of such triples .
Input
The first line contains an integer . ()
Output
Print the number of triples that satisfy the condition.