Unique right triangle
Time limit1sMemory limit256 MB
Count the perimeters up to N that form exactly one integer-sided right triangle.
- Level
Medium7 of 10
- Topics
- Number theory, Array, Prefix sum
- Solved
- No attempts yet
Problem
12cm is the shortest length of string that can be bent into a right triangle whose three sides are all integers. Here are a few more such lengths.
- 12cm: (3, 4, 5)
- 24cm: (6, 8, 10)
- 30cm: (5, 12, 13)
- 36cm: (9, 12, 15)
- 40cm: (8, 15, 17)
- 48cm: (12, 16, 20)
A string of length 20cm cannot be bent into a right triangle with integer sides in any way.
Some lengths give several different right triangles. For example, 120cm gives three.
- 120cm: (30, 40, 50), (20, 48, 52), (24, 45, 51)
Let be the length of the string. Among the values , how many give exactly one right triangle with integer sides? Triangles that differ only in the order of the sides count as the same triangle.
Input
The input holds several tests. Each line has one integer , and the tests continue to the end of the input. ()
Output
For each test, print on its own line the number of values that give exactly one right triangle with integer sides.