Loading...
Loading...
Riya is designing a square seating plan for a college fest. She has x chairs and wants the largest square of k rows and k columns that fits, so k × k must be at most x.
Print the largest such whole number k. This is the square root of x, rounded down.
Example 1
Input
20
Output
4
4 × 4 = 16 fits, but 5 × 5 = 25 is more than 20.
Example 2
Input
49
Output
7
7 × 7 = 49 is exactly x.
Try the problem first. Open one hint at a time.
The answer k is somewhere between 0 and 10^9, because (10^9)² = 10^18.
If m × m ≤ x, then every number below m also works. So the "works" numbers form one block, then the rest fail.
Search that range: when the middle works, remember it and try bigger; when it fails, try smaller.
Keep the upper end at 10^9 so that mid * mid never goes past the long limit.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor