• + 0 comments

    Here is my python code (simple brute force):

    def kaprekarNumbers(p, q):
        arr = []
        for i in range(p, q + 1):
            curr = str(i ** 2)
            d1 = curr[:len(curr) // 2] if len(curr) > 1 else "0"
            d2 = curr[len(curr) // 2:] if len(curr) > 1 else curr
            if int(d1) + int(d2) == i:
                arr.append(str(i))
        print(" ".join(arr) if arr != [] else "INVALID RANGE")