求100 - 999之间的所有水仙花数。

水仙花数是这个数的每一位上数字的立方和等于这个数本身,比如153 = 1 ^ 3 + 5 ^ 3 + 3 ^ 3 = 1 + 125 + 27 = 153

i=100

while i<=999:

a=int(i/100)

b=int((i%100)/10)

c=i%10

if i==a3+b3+c**3:

print(i)

i+=1

猜你喜欢

转载自blog.csdn.net/weixin_43290492/article/details/90144318