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:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Count numbers in a range having GCD of powers of prime factors equal to 1
- Count different numbers that can be generated such that there digits sum is equal to 'n'
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Count of Numbers in Range where the number does not contain more than K non zero digits
- Count Numbers with N digits which consists of even number of 0’s
- Count Numbers with N digits which consists of odd number of 0's
- Form a number using corner digits of powers
- Count the number of digits of palindrome numbers in an array
- Count of numbers in Array ending with digits of number N
- Find all powers of 2 less than or equal to a given number
- Distinct powers of a number N such that the sum is equal to K
- Count total number of N digit numbers such that the difference between sum of even and odd digits is 1
- Count the numbers < N which have equal number of divisors as K
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Count pairs of natural numbers with GCD equal to given number
- Generate k digit numbers with digits in strictly increasing order
- Count of numbers upto N digits formed using digits 0 to K-1 without any adjacent 0s
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Sum of first N natural numbers by taking powers of 2 as negative number
- Print all non-increasing sequences of sum equal to a given number x
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.