Number of n digits which are equal to sum of nth power of digit.
Program
for i in range(1,1000):
num=i
n=len(str(i))
sum1=0
i=str(i)
for digit in i:
sum1=sum1+int(digit)**n
if sum1==num:
print(num)
Output
1
2
3
4
5
6
7
8
9
153
370
371
407
Example
To check 153 is armstrong number or not.
153
Length of number 153 is 3
=1^3+5^3+3^3
=1+125+27
=153
So that sum 153 equal to the original number 153 that number is armstrong number.
0 Comments