Show problems as
Classic problem #633MediumMathTwo PointersBinary Search

Sum of Square Numbers

Real-world version: Two Square Courts From One Delivery
Tracked in this browser only
Read Sum of Square Numbers on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A groundworks firm has taken delivery of exactly c identical square slabs and wants to lay two square courts with them, using up every slab and cutting none.

A court is a solid square block, so a court whose side measures s slabs swallows s * s slabs. A side of zero slabs is allowed and simply means that court is not laid at all.

Return true if some choice of the two side lengths uses the delivery up exactly, and false if some slabs would always be left over.

Examples

Example 1

Input
c = 8
Output
true

Two courts of side two each swallow four slabs, which accounts for all eight.

Example 2

Input
c = 6
Output
false

Every pairing of side lengths either leaves slabs in the yard or calls for more than were delivered.

Example 3

Input
c = 26
Output
true

A court of side five swallows twenty-five slabs and a court of side one swallows the last slab.

Example 4

Input
c = 0
Output
true

Nothing was delivered, and two courts of side zero use up nothing.

Constraints

  • 0 <= c <= 2^31 - 1

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def judge_square_sum(c: int) -> bool:
Java
public boolean judgeSquareSum(int c)