def is_strong_number(n):
"""
Check if a number is a strong number.
A strong number is a number whose sum of factorials of digits equals itself.
Args:
n (int): The number to check
Returns:
bool: True if n is a strong number, False otherwise
"""
# Handle negative numbers
if n < 0:
return False
# Precompute factorials for digits 0-9
factorials = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
# Calculate sum of factorials of digits
original = n
factorial_sum = 0
while n > 0:
digit = n % 10
factorial_sum += factorials[digit]
n //= 10
return factorial_sum == original
# Example usage
test_numbers = [1, 2, 145, 40585, 100, 1234]
for num in test_numbers:
if is_strong_number(num):
print(f"{num} is a strong number")
else:
print(f"{num} is not a strong number")
# Output:
# 1 is a strong number
# 2 is a strong number
# 145 is a strong number
# 40585 is a strong number
# 100 is not a strong number
# 1234 is not a strong number
The only known strong numbers in base 10 are: 1, 2, 145, and 40585.