Finding nearest integer to the square root of a positive integer

1.1k Views Asked by At

Can we follow any general method so that we may describe the integer nearest to the square root of a positive integer $n$?

I considered the greatest integer function (GIF) or the least integer function (LIF), but that is of no help in generalization. How do I know whether $\sqrt{n} = k$ (say) is nearest to GIF of $k$, or LIF of $k$? Is there any specific method for dealing with this?

1

There are 1 best solutions below

0
On BEST ANSWER

Let $\sqrt{n}$ be a non-integer between $k$ and $k+1$. Note that $(k+0.5)^2=k^2+k+0.25$.

So $\sqrt{n}$ is closer to $k$ if $k^2<n\le k^2+k$.

$\sqrt{n}$ is closer to $k+1$ if $k^2+k<n\le k^2+2k$.