Given two integers N and K, the task is to check whether N can be made a perfect cube after adding to or subtracting from K to or from it.
Input: N = 7, K = 1
7 + 1 = 8 which is a perfect cube (23 = 8)
Input: N = 5, K = 4
5 – 4 = 1 which is a perfect cube (13 = 1)
Approach: The simplest way to solve this problem is to check whether either (N + K) or (N – K) is a perfect cube or not.
- Check whether (N + K) is a perfect cube or not
- If not, then check whether (N – K) is a perfect cube or not.
- If both are not perfect cube, then print “No”, else print “Yes”.
- In order to check whether a number is a perfect cube or not, the easiest way is to find the cube of the floor value of cube root of the number, and then check whether this cube is same as the number or not.
if(N3 == (floor(∛N))3) Then N is a perfect cube
Below is the implementation of the above approach:
Yes Yes No
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.
- Check whether the number can be made perfect square after adding 1
- Check whether the number can be made perfect square after adding K
- Check if given intervals can be made non-overlapping by adding/subtracting some X
- C Program to check whether a number is a Perfect Cube or not
- Check whether the number can be made palindromic after adding K
- Count numbers upto N which are both perfect square and perfect cube
- Minimize adding odd and subtracting even numbers to make all array elements equal to K
- Number of times the largest Perfect Cube can be subtracted from N
- Percentage increase in volume of the cube if a side of cube is increased by a given percentage
- Check if number formed by joining two Numbers is Perfect Cube
- Minimum sum after subtracting multiples of k from the elements of the array
- Minimum sum of the elements of an array after subtracting smaller elements from larger
- Count all triplets whose sum is equal to a perfect cube
- Perfect cube greater than a given number
- Largest number in an array that is not a perfect cube
- Largest perfect cube number in an Array
- Smallest perfect Cube divisible by all elements of an array
- Smallest perfect cube in an array
- Print N numbers such that their sum is a Perfect Cube
- Minimum divisor of a number to make the number perfect cube
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.