Is there a way to check if a number is square number?
For example, we know that $4$ is a square number because $2^2=2$ and $9$ is a square number because $3^2=9$. But for example $5$ is not a square number.
Is there a way to check if a number is square number?
For example, we know that $4$ is a square number because $2^2=2$ and $9$ is a square number because $3^2=9$. But for example $5$ is not a square number.
As a practical matter, the method “guess the square root, then check if you're right” works surprisingly well, and much better than it sounds. The details will depend on whether you are doing a paper-and-pencil calculation or implementing a computer algorithm.
For the paper-and-pencil version, it will go something like this. Let's do an example, say $n=11\,486$. Let's let $s$ be the largest integer whose square root is $n$ or smaller. If $s^2=n$ exactly, then $n$ is a perfect square.
$n$ has 5 digits, so $s$ will have 3 digits. (In general, if $n$ has $d$ digits, $s$ will have $\frac{d+1}2$. Round down.) And $n$ begins with the digit 1
, so that $s$ must be somewhere between 100 and 199. In fact we can do better. $\sqrt2\approx 1.41$ so $s$ can't be bigger than $141$, because $141^2$ must be close to $20\,000$. (Note that I got this without any actual multiplication, just from knowing the first three digits of $\sqrt 2$. But even if you know only the first two digits, you can still see that $s$ can't be much bigger than $140$.) And indeed $s$ must be pretty close to the bottom of the range $100\ldots 141$ because $11\,486$ is pretty close to the bottom of the range $10\,000\ldots20\,000$.
So let's guess that perhaps $s$ is around $110$. Now $11^2=121$ so $110^2 = 12100$ which is too big. So $s$ is less than $110$.
We can proceed from this and simply make another guess, well, $110$ didn't work, so let's try $105$. Or we could observe that if $n$ were a perfect square then $s$ would have to end with a $4$ or a $6$, because $n$ ends with a $6$, so it would have to be either $104$ or $106$, and since neither one works, $n$ wasn't a square. We can do even better if we are willing to use some actual mathematics. $110^2$ was too big by around $700$. If we divide this by $2$, then by our guess $110$, we get around $3$; this is roughly the amount by which our guess of $110$ was too big! Instead of $110$ we should try $107$. Squaring $107$ we get $11\,449$ (that's $10\,000+2\cdot700+49$, which is just a bit less than $n$, so we've found our $s$, and this shows that while $11\,449$ is a square, $11\,486$ can't be; it is too close to $11\,449$. (The next square after $107^2$ is $107^2 + 107 + 108$, but if you estimate $11\,486-11\,449$ it's clearly a lot less than that.)
Well, that was fun. Let's do another. Is $n=190\,969$ a square? It's six digits long so the square root $s$ will be three digits (or put another way, $1\,000^2 = 1\,000\,000$, which is much too big), and it must be between $400$ (whose square is $160\,000$) and $500$ (whose square is $250\,000$). We see that $400^2$ is too small by about $30\,000$. We should increase our guess by around $\frac{30\,000}{800} \approx 37$. Maybe $437$ is the number we want? The last digit is right, so we multiply it out, we find that it is! $437^2 = 190\,969$ exactly.
For paper and pencil calculation, you can put together a lot of miscellaneous number knowledge:
Perhaps most important:
Don't forget that you're doing integer calculations. They don't have to be precise; they only have to be close enough. If you have to divide $\frac{700}{2\cdot 110}$, calculating $3.1818$ is a waste of time. It's just as good, and much easier, to say “eh, roughly $3$”.
For computer calculation, the situation is different. You can take out all the tricky parts and replace them with straight calculation, because the computer is bad at tricky stuff and great at calculation. The computer doesn't care that $(a+b)^2$ is close to $a^2 + 2ab$, because for the computer calculating $(a+b)^2$ is easier than calculating $a^2 + 2ab$. For the computer, getting an exact answer $\frac{700}{2\cdot 110} = 3.1818\ldots$ is easier than saying “eh, roughly $3$.” So for computer calculation, we can just use the Babylonian method directly: make a guess $g$, then repeatedly adjust $g$ until you get the right answer.