Skip to content

Instantly share code, notes, and snippets.

@jatinsharrma
Created March 2, 2019 12:33
Show Gist options
  • Save jatinsharrma/0154386de7cd3e6d7aa04c3b50a6518f to your computer and use it in GitHub Desktop.
Save jatinsharrma/0154386de7cd3e6d7aa04c3b50a6518f to your computer and use it in GitHub Desktop.
Program calculate Kaprekar numbers in range(1 and 100000)
# In mathematics, a non-negative integer is called a "Kaprekar number" for a given base if the representation of its square in that base can be split into two parts that add up to the original number, with the proviso that the part formed from the low-order digits of the square must be non-zero—although it is allowed to include leading zeroes. For instance, 45 is a Kaprekar number, because 452 = 2025 and 20 + 25 = 45. The number 1 is Kaprekar in every base, because 12 = 01 in any base, and 0 + 1 = 1. Kaprekar numbers are named after D. R. Kaprekar.
#this program calculate Kaprekar numbers between 1 and 100000
#this is shortform of the bigger program i wrote "Kaprekar number.py" that program can calculate a larger range. See my git.
#can increase the range by adding more Kaprekar number in all list.
start = int(input())
end = int(input())
all = [1, 9, 45, 55, 99, 297, 703, 999, 2223, 2728, 4950, 5050, 7272, 7777, 9999, 17344, 22222, 77778, 82656, 95121, 99999]
ans = [str(i) for i in all if i>=start and i<=end]
if ans:
print (' '.join(ans))
else:
print ('INVALID RANGE')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment