Description

Given a non-negative integer x, return the square root of x rounded down to the nearest integer. Use Newton's method for calculation.

Examples

Input:x = 8
Output:2
Explanation:

√8 = 2.82..., rounded down to 2.

Input:x = 0
Output:0
Explanation:

√0 = 0 exactly, so the result is 0. This tests the edge case of the minimum possible input.

Input:x = 15
Output:3
Explanation:

√15 = 3.872..., rounded down to 3. This demonstrates rounding down when the square root is not a perfect integer.

Constraints

  • 0 ≤ x ≤ 2³¹ - 1

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!