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]
- 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
- Number of times the largest perfect square number can be subtracted from N
- Given number of matches played, find number of teams in tournament
- Number of possible permutations when absolute difference between number of elements to the right and left are given
- Number of times a number can be replaced by the sum of its digits until it only contains one digit
- Print a number strictly less than a given number such that all its digits are distinct.
- Find the largest good number in the divisors of given number N
- Find maximum number that can be formed using digits of a given number
- Find the total number of composite factor for a given number
- Count number of ways to divide a number in 4 parts
- Find the number of ways to divide number into four parts such that a = c and b = d
- Check whether all the rotations of a given number is greater than or equal to the given number or not
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Mithun Kumar