Given a number n, the task is to print all the numbers less than or equal to n which are perfect cubes as well as the eventual sum of their digits is 1.
Input: n = 100
Output: 1 64
64 = 6 + 4 = 10 = 1 + 0 = 1
Input: n = 1000
Output: 1 64 343 1000
Approach: For every perfect cube less than or equal to n keep on calculating the sum of its digits until the number is reduced to a single digit ( O(1) approach here ), if this digit is 1 then print the perfect cube else skip to the next perfect cube below n until all the perfect cubes have been considered.
Below is the implementation of the above approach:
1 64 343 1000
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.
- Maximum of sum and product of digits until number is reduced to a single digit
- Largest number less than N with digit sum greater than the digit sum of N
- Count of N-digit numbers having digit XOR as single digit
- Smallest and Largest N-digit perfect cubes
- Check if sum of array can be reduced to zero by repetitively reducing array element by their index value
- Count numbers whose maximum sum of distinct digit-sum is less than or equals M
- Check if frequency of each digit is less than the digit
- Finding sum of digits of a number until sum becomes single digit
- Number of perfect cubes between two given numbers
- Count of Numbers such that difference between the number and sum of its digits not less than L
- Sum of all Perfect Cubes lying in the range [L, R] for Q queries
- Check if a number can be represented as sum of two consecutive perfect cubes
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Sum of Digits in a^n till a single digit
- Smallest N digit number whose sum of square of digits is a Perfect Square
- Check if a number is a perfect square having all its digits as a perfect square
- Perfect cubes in a range
- Count number less than N which are product of perfect squares
- Print all numbers less than N with at-most 2 unique digits
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.