Proof of the Pythagorean Theorem
Time limit1sMemory limit1024 MB
Count the ordered pairs (a, b) of positive integers up to N for which the yellow square's area is an integer multiple of one blue triangle's area.
- Level
Medium5 of 10
- Topics
- Math, Number theory
- Solved
- No attempts yet
Problem
The Pythagorean theorem states the following.
In a right triangle, let the hypotenuse have length and the other two sides have lengths and . Then .
There are so many proofs of the Pythagorean theorem that they fill a whole book. Hyunmin claims that the root of them all is the method below, which is said to have been devised by Pythagoras.

Minjae, who was listening nearby, asked the following to pull Hyunmin out of his obsession with Pythagoras.
"In the figure above, and are positive integers at most . What conditions must they satisfy for the area of the yellow square to be an integer multiple of the area of one blue triangle?"
Help Hyunmin find the answer and rescue him from Pythagoras.
Input
The first line contains the number of test cases .
Each of the next lines contains one test case .
Output
For each test case, print on its own line the number of ordered pairs that satisfy the condition.