Sum of Square Numbers

Given a non-negative integer c, decide whether there are two integers a and b such that a² + b² = c.

30:00

Sum of Square Numbers
medium
Free written solution
Topics
Companies

Given a non-negative integer c, decide whether there are two integers a and b such that a² + b² = c.

Example 1:
Input: {"c":5}
Output: true
Constraints:
  • 0≤c≤231−10 \leq c \leq 2^{31} - 1

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"c":5}

We want two whole numbers whose squares add up to exactly 5. Both must lie between 0 and sqrt(5) ≈ 2.24.

0²=0+2²=4?c5

a² + b² = -

candidates 0 .. 2

0
1
2
a▼
b▼

ruled out (none yet)

Variables
VariableValue
c5
a0
b2
total-
DepthFunction Call
Stack empty
0/5