酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

水仙花数的定义:一个三位数(100~999)的各位数的立方和等于它本身。例如,153是一个三位数的水仙花数,因为 1^3 + 5^3+ 3^3 =1 + 125 + 27=153 题目大意:输入一个数n,求100到整数n的区间内有多少个水仙花数m,并打印水仙花数的数量m,用空格分隔。若区间没有水仙花数,则输出not found. 输入描述: 输入一个整数n 输出描述: 水仙花数的数量m ,(找不到打印not found) 示例1:输入 :154 输出 : 1 示例2:输入 101 输出 :not found

以下是使用 Python 语言解决此问题的代码: ```python def is_narcissistic_number(num): digit1 = num // 100 digit2 = (num // 10) % 10 digit3 = num % 10 if digit13 + digit23 + digit33 == num: return True else: return False n = int(input()) count = 0 for i in range(100, n + 1): if is_narcissistic_number(i): count += 1 if count == 0: print("not found") else: print(count) ``` [2024-10-18 18:05:29 | AI写代码神器 | 161点数解答]

相关提问