Problems > Integer Square Root > Editorial

Integer Square Root — Solution & Editorial

Back to the Problem

Binary search the answer in [0, 109]: mid² ≤ N moves the lower bound up. Floating-point sqrt is off by one near 1018.

Complexity: O(log N)