Armstrong numbers between two intervals
Write a program to print all the Armstrong numbers in the given range A to B(including A and B). An N-digit number is an Armstrong number if the number equals the sum of the Nth power of its digit.
Input
The first line has an integer A.
The second line has an integer B.
Output
Print all Armstrong numbers separated by a space.
If there are no Armstrong numbers in the given range,print -1.
Sample Input 1
1
3
Sample Input 1
1 2 3
Sample Input 2
10
15
Sample Input 2
-1
a = int(input())
b = int(input())
if a > b:
a, b = b, a
for i in range(a,b+1):
s = str(i)
l = len(s)
tmp = 0
for n in s:
tmp += int(n)**l
if tmp == i:
print(i)
Comments
Leave a comment