
Problem
Solution
Submissions
Strong Number Checking
Certification: Basic Level
Accuracy: 75%
Submissions: 4
Points: 10
Write a C++ program to check if a given number is a strong number. A strong number is a number where the sum of the factorial of its digits is equal to the number itself.
Example 1
- Input: number = 145
- Output: true
- Explanation:
- Step 1: Calculate the factorial of each digit in 145.
- Step 2: 1! = 1, 4! = 24, 5! = 120.
- Step 3: Sum the factorials: 1 + 24 + 120 = 145.
- Step 4: Since the sum 145 equals the original number 145, return true.
Example 2
- Input: number = 123
- Output: false
- Explanation:
- Step 1: Calculate the factorial of each digit in 123.
- Step 2: 1! = 1, 2! = 2, 3! = 6.
- Step 3: Sum the factorials: 1 + 2 + 6 = 9.
- Step 4: Since the sum 9 does not equal the original number 123, return false.
Constraints
- 1 ≤ number ≤ 10^6
- Time Complexity: O(n), where n is the number of digits in the number
- Space Complexity: O(1)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Calculate the factorial of each digit of the number.
- Sum the factorials and compare the result with the original number.
- Handle edge cases where the number is 0 or 1 separately.