Strong Numbers are the numbers whose sum of factorial of digits is equal to the original number. Given a number, check if it is a Strong Number or not.
Input : n = 145 Output : Yes Sum of digit factorials = 1! + 4! + 5! = 1 + 24 + 120 = 145 Input : n = 534 Output : No
1) Initialize sum of factorials as 0. 2) For every digit d, do following a) Add d! to sum of factorials. 3) If sum factorials is same as given number, return true. 4) Else return false.
An optimization is to precompute factorials of all numbers from 0 to 10.
This article is contributed by Pramod Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Check if N is Strong Prime
- Program to check whether a number is Proth number or not
- Program to check if N is a Myriagon Number
- Program to check the number is Palindrome or not
- Program to check if N is a Icosagonal Number
- Program to check if N is a Pentagonal Number
- Program to check if N is a Dodecagonal Number
- Program to check Plus Perfect Number
- Program to check for Peterson number
- Program to check if N is a Star Number
- Program to check if N is a Decagonal Number
- Program to check if N is a Nonagonal Number
- Program to check if N is a Enneadecagonal Number
- Program to check if N is a Heptadecagonal Number
- Program to check if N is a Icosidigonal Number