Square Root Integer Part
EasyPractice library · +10 XPbinary searchbinary search on the answer
Given a non-negative integer N, find the largest integer x such that x * x <= N. This is equivalent to finding the integer part of the square root of N.
Input
A single line containing the non-negative integer N (0 <= N <= 10^9).
Output
A single line containing the largest integer x such that x * x <= N.
Constraints
0 <= N <= 10^9
Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests
Example 1
Input
10
Output
3
The largest integer x such that x*x <= 10 is 3 (since 3*3=9).
Example 2
Input
16
Output
4
The largest integer x such that x*x <= 16 is 4 (since 4*4=16).
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
10
Example 2 input
16