用Pythons"水仙花数" 是指一个三位整数,其各位数字的 3 次方和等于该数本身。A3+B3+C3=ABC 请按照从小到大的顺序输出所有的 3 位水仙花数,请用英文逗号","分隔输出结果。 输入:无 输出:153,370,371,407,
时间: 2024-06-10 08:05:31 浏览: 154
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身
5星 · 资源好评率100%
The answer to your question is:
To find all 3-digit narcissistic numbers, we need to check each number in the range of 100 to 999, calculate the sum of each digit raised to the power of 3, and then check if the sum is equal to the original number. Here is the Python code to find all 3-digit narcissistic numbers:
narcissistic_numbers = []
for i in range(100, 1000):
a = i // 100
b = (i // 10) % 10
c = i % 10
if (a**3 + b**3 + c**3) == i:
narcissistic_numbers.append(i)
print(', '.join(map(str, narcissistic_numbers)))
The output will be: 153, 370, 371, 407.
阅读全文