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 JavaScript
Four clear steps — a digit-factorial lookup makes the check fast and clear.
Precompute 0! through 9! in a small array (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
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. Each example has a Try it Yourself editor.
Example 1 — Check One Number
Precompute 0!..9!, sum digit factorials, and compare with n.
JavaScript
function isStrongNumber(n) {
const fact = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880];
const original = n;
let total = 0;
while (n > 0) {
const digit = n % 10;
total += fact[digit];
n = Math.floor(n / 10);
}
return total === original;
}
const number = 145;
if (isStrongNumber(number)) {
console.log(number + " is a Strong Number.");
} else {
console.log(number + " is not a Strong Number.");
}
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.
JavaScript
function isStrongNumber(n) {
const fact = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880];
const original = n;
let total = 0;
while (n > 0) {
const digit = n % 10;
total += fact[digit];
n = Math.floor(n / 10);
}
return total === original;
}
console.log("Strong Numbers in the Range 1 to 200:");
let line = "";
for (let i = 1; i <= 200; i++) {
if (isStrongNumber(i)) {
line += i + " ";
}
}
console.log(line.trim());