We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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="")
Modified Kaprekar Numbers
You are viewing a single comment's thread. Return to all comments →
Python3 solution