What I would like to do in my program is to give the program a very large integer as an input, evaluate its square root, then determine if the square root is an integer. This determines whether the input is a square number. If it is, return the square root, if it is not, return False
. My code looks something like this:
n = int(input())
sqrt = n**(1/2)
if sqrt.is_integer():
return int(sqrt)
else:
return False
However, this program is not working correctly with very, very large numbers. For example, when n = 170141183460469231731687303715884105727, the calculated square root value is 1.3043817825332783e+19, and sqrt.is_integer() returns True, when I know this number is a prime number and thus its square root cannot be an integer.
If Python cannot support an arbitrarily large float, is there a way to make Python only determine if the square root of an arbitrarily large integer has decimal places? Thanks in advance.
Btw, I have also tried int(sqrt) == sqrt
. Same result.