To be more accurate in what I'm looking for, I'm trying to express a number as a sum like
N= n²+r where N is the given number and n² is the closest square to it.
An Interesting observation is that n² could be grater than N, which makes r be negative. For example, closest square to 63 would be not 49, but 64 so
$63 = 8² - 1 $
I know I can simply compute the square root in calculator but that's no the idea cause I'm planing using this to approximate square root of big numbers with secondary students.
I was trying to use the fact that every square is $4k$ or $4k±1$
So I was trying to simply make a consecutive division by 4 for trying to express the number in the wished way but it don't always works
EG
$835 = 4(208)+3 = 4(196+12)+3=4 \cdot 14² +51=28²+51$
So, closest square, minor than 835, is $28²$
But, when I do the same with 5361 for eg
$53561 = 4(13390)+1 = 4(4(3347)+2)+1 = 4²\cdot 3347+9 = 4³\cdot 836+57 = 4⁴\cdot 209 + 57 = 4⁴ (14²+13)+57 = 224²+3385 $
Wich is the form but 224² clearly is no the closest square.
Maybe you can give a more optimal ideal, thanks a lot.
Asked
Active
Viewed 140 times
1

OscAr
- 19
-
4See https://en.wikipedia.org/wiki/Integer_square_root – lhf Apr 07 '23 at 15:42
-
@peterwhy Yes, n can be grater than N and that makes that r can be negative. – OscAr Apr 07 '23 at 15:59
-
Then $29^2$ is closer to $835$. – peterwhy Apr 07 '23 at 16:03
-
@peterwhy You're right – OscAr Apr 07 '23 at 16:06
-
@peterwhy the way I was working only takes minor values of N ... :( – OscAr Apr 07 '23 at 16:08
-
1$\lfloor \sqrt{N}+\frac{1}{2} \rfloor^2$, see A053187 – Sil Apr 07 '23 at 16:22
-
The digit-by-digit method was taught in school before there were calculators. I used it in an exam when I forgot my slide rule. If you have a calculator you can modify it to extract about half as many places at a time as you have digits in the calculator. – Ross Millikan Apr 07 '23 at 17:10
-
Newton's method and related iterative approximation schemes yield efficient algorithms, e.g. see here for an explanation of Rudin's approximation of square-roots via the secant method. – Bill Dubuque Apr 07 '23 at 18:27
1 Answers
1
Nice question. Let $f(N)$ be the number whose square is the closest to $N$. Clearly $f(0)=0$ and $f(1)=1$. Define a new function $g(N)$ by $$ g(N) = f(N) - 2f(\left[N/4\right]), $$ where $\left[N/4\right]$ is $N/4$ rounded to the nearest integer. We might expect $g(N)$ to be small... checking directly, it is in fact the case that $|g(N)| \le 1$ for all $N$. (It also has an interesting-looking form, rotating between increasingly long runs of $0$'s, $1$'s, and $-1$'s... but we don't need to find a closed form for this exercise.) So a working recursive algorithm for $f(N)$, which takes $O(\log N)$ steps, is to first find $x=f([N/4])$, and then choose whichever of $\{x-1,x,x+1\}$ has its square closest to $N$.

mjqxxxx
- 41,358