Given an integer N, the task is to count all the integers less than or equal to N that follow the property where the sum of their digits raised to the power (starting from 1 and increased by 1 each time) is equal to the integer itself i.e. if D1D2D3…DN is an N digit number then for it to satisfy the given property (D11 + D22 + D33 + … + DNN) must be equal to D1D2D3…DN.
Input: N = 100
01 = 0
11 = 1
21 = 2
91 = 9
81 + 92 = 8 + 81 = 89
Input: N = 200
Approach: Initialise count = 0 and for every number from 0 to N, find the sum of digits raised to the increasing power and if the resultant sum is equal to the number itself then increment the count. Finally, print the count.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Count array elements having modular inverse under given prime number P equal to itself
- Nth Subset of the Sequence consisting of powers of K in increasing order of their Sum
- Count of N digit Numbers whose sum of every K consecutive digits is equal
- Count of N digit Numbers whose sum of every K consecutive digits is equal | Set 2
- Count numbers in a range having GCD of powers of prime factors equal to 1
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Find K that requires minimum increments or decrements of array elements to obtain a sequence of increasing powers of K
- Distinct powers of a number N such that the sum is equal to K
- Count of n digit numbers whose sum of digits equals to given sum
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Sum of GCD of all numbers upto N with N itself
- Form a number using corner digits of powers
- Find a Number X whose sum with its digits is equal to N
- Smallest number greater than or equal to X whose sum of digits is divisible by Y
- Sum of first N natural numbers by taking powers of 2 as negative number
- Find all powers of 2 less than or equal to a given number
- Count of all even numbers in the range [L, R] whose sum of digits is divisible by 3
- Count of numbers from range [L, R] whose sum of digits is Y
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.