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 C++
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
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
C++ 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.
C++
#include <iostream>
using namespace std;
bool isStrongNumber(int n)
{
int fact[] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880 };
int original = n;
int total = 0;
while (n > 0)
{
int digit = n % 10;
total += fact[digit];
n /= 10;
}
return total == original;
}
int main()
{
int number = 145;
if (isStrongNumber(number))
{
cout << number << " is a Strong Number." << endl;
}
else
{
cout << number << " is not a Strong Number." << endl;
}
return 0;
}
Output
145 is a Strong Number.
How It Works
The fact array 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 method 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.
C++
#include <iostream>
using namespace std;
bool isStrongNumber(int n)
{
int fact[] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880 };
int original = n;
int total = 0;
while (n > 0)
{
int digit = n % 10;
total += fact[digit];
n /= 10;
}
return total == original;
}
int main()
{
cout << "Strong Numbers in the Range 1 to 200:" << endl;
for (int i = 1; i <= 200; i++)
{
if (isStrongNumber(i))
{
cout << i << " ";
}
}
cout << endl;
return 0;
}
Output
Strong Numbers in the Range 1 to 200:
1 2 145
How It Works
Loop i from 1 to 200 inclusive.
Call isStrongNumber(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.
C++
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
const int FACT[] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880 };
int main()
{
int values[] = { 2, 10, 145, 99 };
int count = sizeof(values) / sizeof(values[0]);
for (int i = 0; i < count; i++)
{
int n = values[i];
vector<string> terms;
int total = 0;
int x = n;
while (x > 0)
{
int d = x % 10;
total += FACT[d];
terms.push_back(to_string(d) + "!=" + to_string(FACT[d]));
x /= 10;
}
reverse(terms.begin(), terms.end());
cout << n << ": ";
for (size_t t = 0; t < terms.size(); t++)
{
if (t > 0)
{
cout << " + ";
}
cout << terms[t];
}
cout << " = " << total
<< " -> " << (total == n ? "strong" : "not strong")
<< endl;
}
return 0;
}