Write a Python function to check if a number is a perfect square


Topic: Write a Python function to check if a number is a perfect square

Solution

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



List all Python Programs