Given an integer N, the task is to find the smallest and the largest N digit numbers which are also perfect cubes.
Input: N = 2
Output: 27 64
27 and 64 are the smallest and the largest 2-digit numbers which are also perfect cubes.
Input: N = 3
Output: 125 729
Approach: For increasing values of N starting from N = 1, the series will go on like 8, 64, 729, 9261, ….. for the largest N-digit perfect cube whose Nth term will be pow(ceil(cbrt(pow(10, (n))))-1, 3).
And 1, 27, 125, 1000, ….. for the smallest N-digit perfect cube whose Nth term will be pow(ceil(cbrt(pow(10, (n – 1)))), 3).
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.
- Smallest and Largest N-digit perfect squares
- Perfect cubes in a range
- Number of perfect cubes between two given numbers
- Sum of all Perfect Cubes lying in the range [L, R] for Q queries
- Numbers less than N that are perfect cubes and the sum of their digits reduced to a single digit is 1
- Smallest perfect cube in an array
- Largest number that is not a perfect square
- Largest factor of a given number which is a perfect square
- Largest sub-array whose all elements are perfect squares
- Largest number in an array that is not a perfect cube
- Smallest perfect Cube divisible by all elements of an array
- Smallest N digit number which is a perfect fourth power
- Length of largest subarray whose all elements are Perfect Number
- Largest N digit Octal number which is a Perfect square
- Number of times the largest Perfect Cube can be subtracted from N
- Largest Divisor of a Number not divisible by a perfect square
- Find the Largest N digit perfect square number in Base B
- Find smallest perfect square number A such that N + A is also a perfect square number
- Smallest and Largest sum of two n-digit numbers
- Largest and smallest digit of a number
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.