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
- Maximum number formed from array with K number of adjacent swaps allowed
- Count number of trailing zeros in Binary representation of a number using Bitset
- Count number of triplets with product equal to given number with duplicates allowed
- Find minimum number to be divided to make a number a perfect square
- Find the largest number smaller than integer N with maximum number of set bits
- 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
- Largest number dividing maximum number of elements in the array
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Smallest number dividing minimum number of elements in the array | Set 2
- Smallest number dividing minimum number of elements in the Array
- Number of distinct ways to represent a number as sum of K unique primes
- Number of times the largest perfect square number can be subtracted from N
- Number of ways to split a binary number such that every part is divisible by 2
Improved By : Mithun Kumar