Problems > Perfect Square > Editorial

Perfect Square — Solution & Editorial

Back to the Problem

Take the integer square root and square it back. Floating-point sqrt loses precision at 1018 — use integer square root or adjust the rounded root by ±1.

Complexity: O(1)

Watch out: sqrt(1018) in doubles can be off by one — verify with integer arithmetic.