Fermat’s last theorem (1)

A famous theorem of the mathematician Pierre de Fermat, proved after
more than 300 years, states that, for any natural number n ≥ 3, there is
no natural solution (except for x = 0 or y = 0) to the equation
x^(n) + y^(n) = z^(n).
For n = 2, by contrast, there are infinite non-trivial solutions. For
instance, 3² + 4² = 5², 5² + 12² = 13², 6² + 8² = 10², ….

Write a program that, given four natural numbers a, b, c, d with a ≤ b
and c ≤ d, prints a natural solution to the equation
x² + y² = z²
such that a ≤ x ≤ b and c ≤ y ≤ d.

Input

Input consists of four natural numbers a, b, c, d such that a ≤ b and
c ≤ d.

Output

Print a line following the format of the examples, with a natural
solution to the equation
x² + y² = z²
that fulfills a ≤ x ≤ b and c ≤ y ≤ d. If there is more than one
solution, print the one with the smallest x. If there is a tie in x,
print the solution with the smallest y. If there are no solutions, print
“No solution!”.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:29:07.862Z

© Jutge.org, 2006–2026.
https://jutge.org
