programming-examples/python/Misc/Python program to check if a number is a perfect square.py
2019-11-15 12:59:38 +01:00

12 lines
297 B
Python

def is_perfect_square(n):
x = n // 2
y = set([x])
while x * x != n:
x = (x + (n // x)) // 2
if x in y: return False
y.add(x)
return True
print(is_perfect_square(8))
print(is_perfect_square(9))
print(is_perfect_square(100))