A Krishnamurthy number is a number whose sum of the factorial of digits is equal to the number itself. For example 145, sum of factorial of each digits:
1! + 4! + 5! = 1 + 24 + 120 = 145
Input : 145 Output : YES Explanation: 1! + 4! + 5! = 1 + 24 + 120 = 145, which is equal to input, hence YES. Input : 235 Output : NO Explanation: 2! + 3! + 5! = 2 + 6 + 120 = 128, which is not equal to input, hence NO.
The idea is simple, we compute sum of factorials of all digits and then compare the sum with n.
Interestingly, there are exactly four krishnamurthy numbers i.e. 1, 2, 145 and 40585 known to us.
This article is contributed by DANISH KALEEM. 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.
- Check if a number is divisible by all prime divisors of another number
- Check whether all the rotations of a given number is greater than or equal to the given number or not
- Check if a number with even number of digits is palindrome or not
- Program to check whether the given number is Buzz Number or not
- Check if a number has same number of set and unset bits
- Program to check whether a number is Proth number or not
- Check whether the given number is Euclid Number or not
- Check if a number is Triperfect Number
- Check whether a number is Non-hypotenuse number
- Check if given number is Emirp Number or not
- Check Whether a number is Duck Number or not
- Check if a number is a power of another number
- Check if a number is an Unusual Number or not
- Check if a number is an Achilles number or not
- Check if a number is a Trojan Number
Improved By : nitin mittal