3

I'm looking for an efficient algorithm for minimizing (approximate solutions welcome) an integer function of the form: $$ f(j) = \min\left({jn - \left\lfloor \sqrt {jn} \right\rfloor}^2,{\left\lceil \sqrt {jn} \right\rceil}^2-jn\right)$$ for $1 \le j < n$, where $n$ could be a very large number.

1 Answers1

2

It's $f(n)$ and not $f(j)$, right? Also, the second $|...|$ should be $\lceil...\rceil$, should it not?

That being said, every number has a multiple which is a perfect square. OK, you forbid that by requiring $j<n$. Well, then $j=n-2$ gives you a multiple which is 1 away from the nearest square. So the answer is: 1 for squarefree $n$, 0 for the rest.

Ivan Neretin
  • 12,835
  • For $n=2$, $j=n-2$ violates $1\le j$. However, there the only possible $j$ is $1$, and $\min(2-\lfloor\sqrt 2\rfloor^2, \lceil\sqrt{2}\rceil^2-2)=1$, so your conclusion holds anyway. – celtschk Sep 26 '16 at 20:11
  • The second set of braces are $\lceil ... \rceil$ but the renderer didn't leave adequate space after the radical. – Jesse Booher Sep 26 '16 at 20:31