Strong Number Check

Check if a number is strong number.

Logic BuildingIntermediate
Logic Building
# Take number
num = int(input("Enter a number: "))

# Calculate factorial function
def fact(n):
    if n == 0 or n == 1:
        return 1
    result = 1
    for i in range(2, n + 1):
        result *= i
    return result

# Check strong number
temp = num
strong_sum = 0
while temp > 0:
    digit = temp % 10
    strong_sum += fact(digit)
    temp //= 10

if strong_sum == num:
    print("Strong number")
else:
    print("Not a strong number")

Output

Enter a number: 145
Strong number

Enter a number: 123
Not a strong number

Strong number: sum of factorial of digits equals the number.

Key Concepts:

  • Extract each digit
  • Calculate factorial of digit
  • Sum all factorials
  • Compare with original