A strong number (also called a digital factorial number) equals the sum of the factorials of its digits.
Remember
n is strong ↔ n = sum of d! for each digit d of n
Example: 145
1! + 4! + 5! = 1 + 24 + 120 = 145 → strong
Classic values: 1, 2, 145, 40585
n
Digit factorials
Result
145
1 + 24 + 120
Strong
1
1! = 1
Strong
10
1! + 0! = 2
Not strong
40585
4!+0!+5!+8!+5!
Strong
Approach
How to Check a Strong Number in Python
Four clear steps — a digit-factorial lookup makes the check fast and clear.
Precompute 0! through 9! in a small list (digits never need more).
Copy n, then peel digits with n % 10.
Add fact[digit] for each digit.
Compare the total with the original number.
Method
Idea
Time
Best for
Lookup + digit loop
Add fact[d] for each digit
O(digits)
Interviews, single checks
Range scan
Reuse the helper for each value
O(N log N)
Listing strong numbers
Trace terms
Print each d! contribution
O(digits)
Debugging / teaching
Pseudocode
Pseudocode
fact = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
function IsStrong(n):
if n <= 0:
return false // beginner rule: positive only
original = n
total = 0
while n > 0:
digit = n mod 10
total = total + fact[digit]
n = n / 10
return total == original
Peel digits right to left, add factorials, then compare.
Calculation
n = 145
Digit 5: 5! = 120 total = 120
Digit 4: 4! = 24 total = 144
Digit 1: 1! = 1 total = 145
145 == 145 → strong
Counter-example: 10
0! + 1! = 1 + 1 = 2 ≠ 10 → not strong
Code
Python Programs
Start with a single-value check using a factorial lookup. Then list strong numbers in a range, and finish with a term-by-term trace.
Example 1 — Check One Number
Precompute 0!..9!, sum digit factorials, and compare with n.
python
FACT = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
def is_strong_number(n: int) -> bool:
original = n
total = 0
while n > 0:
digit = n % 10
total += FACT[digit]
n //= 10
return total == original
number = 145
if is_strong_number(number):
print(f"{number} is a Strong Number.")
else:
print(f"{number} is not a Strong Number.")
Output
145 is a Strong Number.
How It Works
The FACT list stores every digit factorial once.
Save original because the loop destroys n.
Each step takes n % 10 and adds FACT[digit].
For 145: 120 + 24 + 1 = 145, so the function returns True.
Never recompute factorial from scratch inside the digit loop.
Example 2 — Strong Numbers from 1 to 200
Reuse the helper to print every strong value in a small band.
python
FACT = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
def is_strong_number(n: int) -> bool:
original = n
total = 0
while n > 0:
digit = n % 10
total += FACT[digit]
n //= 10
return total == original
print("Strong Numbers in the Range 1 to 200:")
for i in range(1, 201):
if is_strong_number(i):
print(i, end=" ")
print()
Output
Strong Numbers in the Range 1 to 200:
1 2 145
How It Works
Loop i from 1 to 200 inclusive.
Call is_strong_number(i) for each value.
Print matches only: 1, 2, and 145.
The next famous strong number, 40585, is far above 200.
This is the usual interview follow-up after a single check.
Example 3 — Trace Digit Factorials
Print each d! term so you can see why a candidate passes or fails.
python
FACT = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
values = [2, 10, 145, 99]
for n in values:
terms = []
total = 0
x = n
while x > 0:
d = x % 10
total += FACT[d]
terms.append(f"{d}!={FACT[d]}")
x //= 10
terms.reverse()
label = "strong" if total == n else "not strong"
print(f"{n}: {' + '.join(terms)} = {total} -> {label}")