30:00
Given a non-negative integer c, decide whether there are two integers a and b such that a² + b² = c.
0≤c≤231−10 \leq c \leq 2^{31} - 10≤c≤231−1
Run code to see results.
We want two whole numbers whose squares add up to exactly 5. Both must lie between 0 and sqrt(5) ≈ 2.24.
a² + b² = -
candidates 0 .. 2
ruled out (none yet)
Decide whether a non-negative integer c can be written as a² + b² for some integers a and b. Both numbers must sit between 0 and sqrt(c), so two pointers can sweep that range from both ends.