Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/for-pifagor-uchliklari

Pythagorean triples

Medium 1000 ms 64 MB 49%
Share

A positive integer $N$ is given. Find all Pythagorean triples of positive integers $(a, b, c)$ satisfying:

$$a^{2} + b^{2} = c^{2}, \qquad a \lt b \lt c \le N$$

A right triangle and Pythagorean triples

Input

One positive integer $N$.

Output

Each triple on a separate line: $a$, $b$, $c$ separated by spaces. The triples are ordered by increasing $a$, and for equal $a$ by increasing $b$. The last line contains the number of triples (if there are none, just 0).

Note

$1 \le N \le 100$

Examples

Input #1
13
Output #1
3 4 5
5 12 13
6 8 10
3
Input #2
4
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.