What’s a good algorithm to determine if an input is a perfect square? [duplicate]
bool IsPerfectSquare(long input) { long closestRoot = (long) Math.Sqrt(input); return input == closestRoot * closestRoot; } This may get away from some of the problems of just checking “is the square root an integer” but possibly not all. You potentially need to get a little bit funkier: bool IsPerfectSquare(long input) { double root = Math.Sqrt(input); … Read more