• + 0 comments

    Python3 solution

    def kaprekarNumbers(p, q):
            nums = []
            for i in range(p,q+1):
                    d, sq = len(str(i)) ,str(i**2)
                    if i ==1 or(len(str(i*i))> d and i == int(sq[-d:])+int(sq[:-d]) and int(sq[d:])!=0):
                            nums.append(i)
            if len(nums) == 0:
                    print('INVALID RANGE')
            else:               
                    print(*nums, end="")