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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check Whether a number is Duck Number or not
- Program to check whether the given number is Buzz Number or not
- Check whether a given number N is a Nude Number or not
- Check whether a given number is an ugly number or not
- Check if LCM of array elements is divisible by a prime number or not
- Check if a number is Full Fibonacci or not
- Check if the product of digit sum and its reverse equals the number or not
- Check whether the number formed by concatenating two numbers is a perfect square or not
- Python program to check whether a number is Prime or not
- Check if the number is divisible 43 or not
- Check if the given number is divisible by 71 or not
- Check if a number is divisible by 31 or not
- Check if a number is divisible by 47 or not
- Program to check if N is a Hexagonal Number or not
- Check whether the binary equivalent of a number ends with given string or not
- C Program to check whether a number is a Perfect Cube or not
- Program to check if a date is valid or not
- Python program to check if a string is palindrome or not
- Check if two numbers are co-prime or not
- Check whether triangle is valid or not if sides are given