跳到内容
🛠️ToolsShed

Narcissistic Number Checker

检查数字是否为自恋数(Armstrong数),查找达到给定限制的所有自恋数。

查找指定范围内的所有自恋数

什么是自恋数?

A narcissistic number (Armstrong number) equals the sum of its digits each raised to the power of the digit count. Example: 153 = 1^3 + 5^3 + 3^3 = 153.

关于此工具

自恋数(也称为阿姆斯特朗数)是一个数字,其等于自身各位数字的幂次和,幂次为该数字的位数。例如,153是自恋数,因为1³ + 5³ + 3³ = 153。这些数字在数学上是有趣的奇异现象,在数系中罕见出现,使其成为探索和理解的乐趣所在。

使用此检查器,只需输入任意正整数,该工具将立即判断它是否为自恋数。所有计算都在浏览器中执行,因此无需创建账户或担心隐私问题。它支持从9这样的小数字到更大的数字,帮助您快速验证数学性质。

自恋数受到数学爱好者、学习数论的学生和探索计算数学的程序员的欢迎。自恋数的完整列表是有限的且文献充分,使这个工具对数学模式的验证和教育探索非常有用。

常见问题

代码实现

def is_narcissistic(n: int) -> bool:
    """Check if n is a narcissistic (Armstrong) number."""
    digits = str(n)
    power = len(digits)
    return sum(int(d) ** power for d in digits) == n

def find_narcissistic(limit: int) -> list[int]:
    """Find all narcissistic numbers up to limit."""
    return [n for n in range(limit + 1) if is_narcissistic(n)]

# Check specific numbers
for n in [153, 370, 371, 407, 1634, 9474]:
    digits = [int(d) for d in str(n)]
    power = len(str(n))
    breakdown = " + ".join(f"{d}^{power}" for d in digits)
    result = sum(d ** power for d in digits)
    print(f"{n}: {breakdown} = {result} {'✓' if result == n else '✗'}")

# Find all up to 10000
print("\nAll narcissistic numbers up to 10000:")
print(find_narcissistic(10000))

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.