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 = 8Output:
2Explanation:
Newton's method iterates: start with guess 4, compute (4 + 8/4)/2 = 3, then (3 + 8/3)/2 = 2.83..., converging to 2.82. Floor gives 2.
Input:
x = 0Output:
0Explanation:
√0 = 0 exactly, so the result is 0. This tests the edge case of the minimum possible input.
Input:
x = 15Output:
3Explanation:
√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