Showing posts with label perfect-square. Show all posts
Showing posts with label perfect-square. Show all posts

Friday, May 25, 2012

Fastest way to determine if an integer"s square root is an integer


I'm looking for the fastest way to determine if a long value is a perfect square (i.e. its square root is another integer). I've done it the easy way, by using the built-in Math.sqrt() function, but I'm wondering if there is a way to do it faster by restricting yourself to integer-only domain. Maintaining a lookup table is impratical (since there are about 2 31.5 integers whose square is less than 2 63 ).