Given a number “n”, find if it is Disarium or not. A number is called Disarium if sum of its digits powered with their respective positions is equal to the number itself.
Input : n = 135 Output : Yes 1^1 + 3^2 + 5^3 = 135 Therefore, 135 is a Disarium number Input : n = 89 Output : Yes 8^1+9^2 = 89 Therefore, 89 is a Disarium number Input : n = 80 Output : No 8^1 + 0^2 = 8
The idea is to fist count digits in given numbers. Once we have count, we traverse all digits from right most (using % operator), raise its power to digit count and decrement the digit count.
Below is implementation of above idea.
This article is contributed by Sahil Chhabra(KILLER). 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- 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
- Number of possible permutations when absolute difference between number of elements to the right and left are given
- 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
- Count number of ways to divide a number in 4 parts
- Build Lowest Number by Removing n digits from a given number
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Find the number of jumps to reach X in the number line from zero
- Count number of digits after decimal on dividing a number
- Querying maximum number of divisors that a number in a given range has
- Program to Convert Octal Number to Binary Number
- Count the number of operations required to reduce the given number