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
- Maximum of sum and product of digits until number is reduced to a single digit
- Smallest and Largest N-digit perfect cubes
- Sum of Digits in a^n till a single digit
- Finding sum of digits of a number until sum becomes single digit
- Check whether a number can be expressed as a product of single digit numbers
- Squares of numbers with repeated single digits | Set 1 (3, 6 and 9)
- Perfect cubes in a range
- Print all n-digit numbers whose sum of digits equals to given sum
- Count numbers formed by given two digit with sum having given digits
- Count of n digit numbers whose sum of digits equals to given sum
- Count of N-digit numbers with all distinct digits
- N digit numbers divisible by 5 formed from the M digits
- Print all n-digit numbers with absolute difference between sum of even and odd digits is 1
- Count total number of N digit numbers such that the difference between sum of even and odd digits is 1
- Generate k digit numbers with digits in strictly increasing order
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.