Revenge of Pythagoras
Time limit1sMemory limit128 MB
Given a natural number A, count the values B > A such that A, B and hypotenuse C form a right triangle with natural C.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
The Pythagorean theorem describes the relationship among the three sides of a right triangle. If the hypotenuse has length and the other two sides have lengths and , then
Among right triangles whose three side lengths are all natural numbers, the best known one is the triangle with sides , , and . For example, when there are exactly two such right triangles.
Given a natural number , how many natural numbers with are there such that the hypotenuse length is also a natural number?
Input
The input consists of several test cases. Each test case is given on a single line as one natural number (). The last line of the input contains a single , which is not processed.
Output
For each test case, print on its own line the number of natural numbers (with ) that form a right triangle whose hypotenuse length is a natural number.