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.
for num in range(p, q + 1):
square = num * num
str_square = str(square)
d = len(str(num))
r = str_square[-d:]
l = str_square[:-d] or '0'
if int(l) + int(r) == num:
res.append(num)
if len(res) == 0:
print('INVALID RANGE')
else:
print(*res)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Modified Kaprekar Numbers
You are viewing a single comment's thread. Return to all comments →
here is the simplified code of python
def kaprekarNumbers(p, q): res = []