3
$\begingroup$

How can I easily check if the square root of a number is a whole number and not a decimal without computing the square rood of said number. I could square root the number ((n^2)^1/2 or sqrt(n^2)) but I do not want to.

$\endgroup$
  • $\begingroup$ @RossMillikan no I meant sqrt(n^2). This will gives me n which is what I am looking for. Lets say n^2 = 36, that would mean n = 6, I want to know if n is an interger $\endgroup$ – Vader Jan 22 '14 at 16:52
  • $\begingroup$ I see what you mean, I fixed it $\endgroup$ – Vader Jan 22 '14 at 17:04
  • $\begingroup$ I would still write it as 'how to check if $n$ is a perfect square', because $n^2$ will always 'square root evenly' - it will always have $n$ as a square root (by convention, $n$ is taken as an integer). $\endgroup$ – Steven Stadnicki Jan 22 '14 at 17:14
  • $\begingroup$ As a small addendum before this (likely) gets closed, I'll note that if you want to have a good 'by hand' method for checking whether a number might be a perfect square, then the best starting point is to memorize all the possible last digits (0, 1, 4, 6, 9) and even last two digits (00, 01, 04, 09; 16; 21, 24, 25, 29; 36; 41, 44, 49; 56; 61, 64, 69; 76; 81, 84, 89; 96 - you can see the pattern here) that a square can have. $\endgroup$ – Steven Stadnicki Jan 22 '14 at 17:27
  • $\begingroup$ @StevenStadnicki I do not plan on doing this by hand, rather implement a function in python $\endgroup$ – Vader Jan 22 '14 at 17:30
1
$\begingroup$

I don't know an easy way. If you know some small factors you can check that they divide $n$ an even number of times. For example if you find that $2^3|n$ but $2^4 \not |n$ you know that $n$ is not a square.

$\endgroup$
  • $\begingroup$ Don't forget computing Jacobi symbols, which will be much more effective when $n$ has few small divisors. $\endgroup$ – Erick Wong Jan 22 '14 at 16:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.