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
- Count number of trailing zeros in Binary representation of a number using Bitset
- 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
- Number of times the largest perfect square number can be subtracted from N
- Given number of matches played, find number of teams in tournament
- Find the smallest number whose digits multiply to a given number n
- Find count of digits in a number that divide the number
- Print a number strictly less than a given number such that all its digits are distinct.
- 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
- Count number of digits after decimal on dividing a number
- Find the number of jumps to reach X in the number line from zero
- Number of digits to be removed to make a number divisible by 3
- Find the total number of composite factor for a given number
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