Definition
Digit factorials
Sum of d! for each digit equals n.
A strong number (digital factorial) equals the sum of the factorials of its digits. Classic examples: 1, 2, 145, 40585. Non-examples: 10 (1!+0!=2), 99 (huge factorial sum). This tutorial covers a 0..9 factorial lookup, a live check, worked Python examples, edge cases, and complexity.
Digit factorials
Sum of d! for each digit equals n.
Precompute
Avoid recomputing factorial each time.
1!+4!+5!
1 + 24 + 120 = 145.
Also strong
1! = 1 and 2! = 2.
Try 145 / 10
See digit factorial terms.
Powers vs !
Different digit tricks.
A strong number equals the sum of the factorials of its digits. So 145 = 1! + 4! + 5! = 1 + 24 + 120, while 10 fails because 1! + 0! = 2.
Interviews love a small lookup table for 0! through 9!, then a digit loop with % 10 and // 10. That is fast, clear, and easy to dry-run on a whiteboard.
It combines digit extraction with factorial basics — and shows why precomputing beats recomputing.
Equals the number.
0! … 9! once.
In range 1..200.
Factorials, not powers.
In short: precompute fact[0..9], sum fact[digit] for every digit, and compare with n.
Given a positive integer n, decide whether the sum of factorials of its digits equals n.
# 145 -> 1! + 4! + 5! = 1 + 24 + 120 = 145 strong
# 2 -> 2! = 2 strong
# 10 -> 1! + 0! = 2 not strong
# 99 -> 9! + 9! = 725760 not strong | Item | Type | Description |
|---|---|---|
n | int | Value to test (n >= 1 in this tutorial). |
| Return | bool | True when sum of digit factorials equals n. |
fact | list | Lookup for 0! through 9!. |
fact = [1,1,2,6,24,120,720,5040,40320,362880]
function isStrong(n):
sum = 0
x = n
while x > 0:
d = x mod 10
sum = sum + fact[d]
x = floor(x / 10)
return sum == n | Method | Idea | Notes |
|---|---|---|
| Lookup + digit loop | Precompute 0..9, sum fact[d] | Interview default |
| Range scan | Call is_strong on each i | Lists 1 2 145 in 1..200 |
| Trace terms | Print each d! contribution | Great for debugging |
| Goal | Pattern |
|---|---|
| Lookup | fact = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880] |
| Next digit | digit = n % 10 |
| Add factorial | total += fact[digit] |
| Drop digit | n //= 10 |
| Verdict | return total == original |
| Early stop | if total > original: return False |
Same definition — different packaging.
is_strong(145)Lookup + digit loop
1..200Finds 1 2 145
print d!Shows each term
! vs ^Factorials, not powers
Reach for a strong check when digit factorials meet equality.
Definition + lookup + digit loop.
Find strong values in a band.
Pairs with factorial tutorials.
Same digit loop, different op.
Most beginner defs start at n >= 1.
Key benefit: one memorable formula — sum of digit factorials — with a tiny constant-size lookup.
Sums digit factorials with a 0..9 lookup and reports the strong verdict.
Three complete Python programs — check 145, list strong numbers from 1 to 200, and print digit-factorial traces for candidates. Click View Output to reveal sample console results.
A lookup table plus a digit loop is the interview-friendly approach.
Precompute 0!..9!, walk digits, and compare the factorial sum with the original value.
def is_strong_number(n: int) -> bool:
fact = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
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.") Digits of 145 are 1, 4, and 5. Factorials are 1, 24, and 120, which sum to 145.
Reuse the helper to list nearby strong values.
Scan the band and print matches. Within 1..200 you only get 1, 2, and 145.
def is_strong_number(n: int) -> bool:
fact = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
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() 1 and 2 are trivial strong numbers; 145 is the first multi-digit hit. The next famous one, 40585, sits well above 200.
Print each digit’s factorial contribution so you can see why a value is strong or not.
FACT = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
def factorial_sum_terms(n: int):
terms = []
total = 0
x = n
while x > 0:
d = x % 10
total += FACT[d]
terms.append(f"{d}!={FACT[d]}")
x //= 10
terms.reverse()
return total, terms
for n in [2, 10, 145, 99]:
total, terms = factorial_sum_terms(n)
label = "strong" if total == n else "not strong"
print(f"{n}: {' + '.join(terms)} = {total} -> {label}") 10 fails because 0! is 1, not 0. 99 blows past the original value immediately because 9! is already huge.
Precompute once; digits never need more.
Use % 10 and // 10.
Accumulate the factorial sum.
Equal means strong; otherwise not.
Compare a classic yes case with a common no case involving 0!.
| n | Digits | Factorial sum | Verdict |
|---|---|---|---|
145 | 1, 4, 5 | 1 + 24 + 120 = 145 | Strong |
2 | 2 | 2 = 2 | Strong |
10 | 1, 0 | 1 + 1 = 2 | Not strong |
99 | 9, 9 | 362880 + 362880 | Not strong |
Remember: 0! = 1, which trips people who expect zero.
Where strong checks show up beyond the interview prompt.
Digit factorials equality.
Example: is_strong(145).
Find strong values in a band.
Example: 1 2 145.
Pairs with factorial tutorials.
Example: related links.
Same digits, different ops.
Example: FAQ.
Print each d! term.
Example: Example 3.
Continue the interview chain.
Example: related CTA.
Pro Tip: open with “n equals the sum of factorials of its digits” and write the 0..9 table first.
Why the lookup-table approach works well for beginners and interviews.
Only ten factorials ever matter.
Dry-run 145 on paper in seconds.
O(digits) with O(1) extras.
Stop if the running sum exceeds n.
Pro Tip: mention early-stop as an optional optimization after the clear baseline loop.
Small habits that keep strong-number solutions interview-ready.
You destroy n while extracting digits.
Never recompute factorial per digit.
It is why 10 is not strong.
Expect 1, 2, and 145.
Say the difference out loud in interviews.
Pro Tip: sanity-check 1, 2, 10, 145, and 99 — if those five behave, your logic is solid.
Mistakes that commonly break strong-number programs.
0! is 1 by definition.
→ Put 1 at fact[0].
Nested factorial loops per digit.
→ Use a lookup list.
Forgetting to save original.
→ Keep original = n.
Using powers instead of factorials.
→ Say the difference explicitly.
Outside this tutorial’s n >= 1 focus.
→ Follow the problem statement.
Handle these before claiming the check is complete.
Most interview versions start from n >= 1.
1! = 1 and 2! = 2.
1! + 0! = 2.
Do not recompute factorial often.
1! + 4! + 5! = 145.
Beyond the 1..200 list.
Handy follow-ups interviewers sometimes ask.
Try these variations to lock in the pattern.
1 2 145.Quick Takeaway: n is strong when sum(fact[digit] for each digit) == n.
| Task | Time | Extra space |
|---|---|---|
| Check one n | O(d) (d = digits) | O(1) |
| Scan 1..U | O(U log U) | O(1) |
| Lookup table | build once | 10 integers |
Digit count grows like log10 n, so a single check is essentially linear in the number of digits.
A strong number equals the sum of the factorials of its digits. Precompute 0! through 9!, walk the digits, and compare — remembering that 0! = 1.
Practice the three examples above, then continue to condensing a number.
Sum of digit factorials equals n.
Classify numbers whose digit factorials sum to themselves.
sum of digit !
Definition0!..9! lookup
Method0! = 1
Edge1 2 145
CheckO(digits)
AnalysisStrong numbers are also called digital factorial numbers. In base 10, the classic examples are 1, 2, 145, and 40585.
Learn how to repeatedly sum digits until a single digit remains.
9 people found this page helpful