水仙花数
(编程题须知) (参考答案)
时间限制:C/C++语言 2000MS;其他语言 4000MS
内存限制:C/C++语言 32768KB;其他语言 557056KB
题目描述:
春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: “水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。 现在要求输出所有在m和n范围内的水仙花数。
import sys
import math
if __name__=="__main__":
myList=[]
try:
while True:
line=sys.stdin.readline().strip()
if line == '':
break
myList.append(list(map(int,line.split())))
except:
pass
for i in xrange(len(myList)):
count=0
resList=[]
for j in xrange(myList[i][1]-myList[i][0]+1):
myVal=myList[i][0]+j
val_1=myVal%10
val_2=(myVal-(myVal//100)*100)//10
val_3=myVal//100
if(myVal==(val_1**3+val_2**3+val_3**3)):
count=count+1
resList.append(myVal)
if(count==0):
print "no"
else:
print " ".join(map(str,resList))