Sum of Square Numbers
Real-world version: Two Square Courts From One DeliveryThe 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.
def judge_square_sum(c: int) -> bool:public boolean judgeSquareSum(int c)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 18 test cases: 18 passed
- Passed: 4 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Minimum Operations to Transform Array into Alternating PrimeReal-world version: Nudging Readings onto Prime ValuesMedium
- Happy NumberReal-world version: Probe Reading SettlesEasy
- Intersection of Two ArraysReal-world version: Shared Scan CodesEasy
- Missing NumberReal-world version: Unclaimed Badge NumberEasy