Given a number N, output all Munchhausen numbers from 1 to n.
Introduction : A Münchhausen number is a number equal to the sum of its digits raised to each digit’s power. It is similar to that of Narcissistic Number.
3435 = 33 + 44 + 33 + 55
One can also be considered as Münchhausen Number because when 1 raised to the power 1 is 1 itself.
Since, the number 3435 can be expressed as sum of each digits of the number when each digits of the numbers are raised to power equivalent to the digits itself i.e., ((3 raised to the power 3) + (4 raised to the power 4) + (3 raised to the power 3) + (5 raised to the power 5)) will give output to the same number i.e. 3435, then the number can be called as Münchhausen Number.
Input : 500 Output : 1 One is the only Münchhausen Number smaller than or equal to 500. Input : 5000 Output : 1 3435 1 and 3435 are the only Münchhausen Numbers smaller than or equal to 5000.
We precompute i raised to power i for every possible digit i where i varies from 0 to 9. After precomputing these values, we traverse through all digits of every number smaller than equal to n and compute sum of digit raised to power digit.
Note : If the definition 0^0 = 0 is adopted, then there are exactly four Münchhausen numbers: 0, 1, 3435, and 438579088 [Source : MathWorld]
- Number of factors of very large number N modulo M where M is any prime number
- Count number of triplets with product equal to given number with duplicates allowed
- Maximum number formed from array with K number of adjacent swaps allowed
- Find minimum number to be divided to make a number a perfect square
- Count number of trailing zeros in Binary representation of a number using Bitset
- Given number of matches played, find number of teams in tournament
- Find smallest possible Number from a given large Number with same count of digits
- Minimum divisor of a number to make the number perfect cube
- Number of possible permutations when absolute difference between number of elements to the right and left are given
- Number of ways to split a binary number such that every part is divisible by 2
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Number of times the largest perfect square number can be subtracted from N
- Largest number dividing maximum number of elements in the array
- Smallest number dividing minimum number of elements in the array | Set 2
- Smallest number dividing minimum number of elements in the Array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Mithun Kumar