Given a number N, the task is to find the next perfect cube greater than N.

**Examples:**

Input: N = 6 Output: 8 8 is a greater number than 6 and is also a perfect cube Input: N = 9 Output: 27

**Approach:**

- Find the cube root of given N.
- Calculate its floor value using floor function in C++.
- Then add 1 to it.
- Print cube of that number.

## C++

`// C++ implementation of above approach ` `#include <cmath> ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Function to find the next perfect cube ` `int` `nextPerfectCube(` `int` `N) ` `{ ` ` ` `int` `nextN = ` `floor` `(cbrt(N)) + 1; ` ` ` ` ` `return` `nextN * nextN * nextN; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `int` `n = 35; ` ` ` ` ` `cout << nextPerfectCube(n); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`//Java implementation of above approach ` `import` `java.util.*; ` `import` `java.lang.*; ` `import` `java.io.*; ` ` ` ` ` ` ` `class` `GFG{ ` `// Function to find the next perfect cube ` `static` `int` `nextPerfectCube(` `int` `N) ` `{ ` ` ` `int` `nextN = (` `int` `)Math.floor(Math.cbrt(N)) + ` `1` `; ` ` ` ` ` `return` `nextN * nextN * nextN; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String args[]) ` `{ ` ` ` `int` `n = ` `35` `; ` ` ` ` ` `System.out.print(nextPerfectCube(n)); ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 implementation of above approach ` ` ` `# from math import everything ` `from` `math ` `import` `*` ` ` `# Function to find the next perfect cube ` `def` `nextPerfectCube(N) : ` ` ` ` ` `nextN ` `=` `floor(N ` `*` `*` `(` `1` `/` `3` `)) ` `+` `1` ` ` ` ` `return` `nextN ` `*` `*` `3` ` ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `n ` `=` `35` ` ` `print` `(nextPerfectCube(n)) ` ` ` `# This code is contributed by ANKITRAI1 ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of above approach ` `using` `System; ` `class` `GFG ` `{ ` `// Function to find the next perfect cube ` `static` `int` `nextPerfectCube(` `int` `N) ` `{ ` ` ` `int` `nextN = (` `int` `)Math.Floor(Math.Pow(N, ` ` ` `(` `double` `)1/3)) + 1; ` ` ` ` ` `return` `nextN * nextN * nextN; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main() ` `{ ` ` ` `int` `n = 35; ` ` ` ` ` `Console.Write(nextPerfectCube(n)); ` `} ` `} ` ` ` `// This code is contributed by ChitraNayal ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of above approach ` ` ` `// from math import everything ` ` ` `// Function to find the next perfect cube ` `function` `nextPerfectCube(` `$N` `) ` `{ ` ` ` `$nextN` `= (int)(` `floor` `(pow(` `$N` `,(1/3))) + 1); ` ` ` ` ` `return` `$nextN` `* ` `$nextN` `* ` `$nextN` `; ` `} ` ` ` `// Driver code ` ` ` ` ` `$n` `= 35; ` ` ` `print` `(nextPerfectCube(` `$n` `)); ` ` ` `// This code is contributed by mits ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

64

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.

## Recommended Posts:

- Count numbers upto N which are both perfect square and perfect cube
- Previous perfect square and cube number smaller than number N
- Smallest subarray of size greater than K with sum greater than a given value
- Percentage increase in volume of the cube if a side of cube is increased by a given percentage
- Find the Next perfect square greater than a given number
- Minimum divisor of a number to make the number perfect cube
- Largest number in an array that is not a perfect cube
- Largest perfect cube number in an Array
- Number of times the largest Perfect Cube can be subtracted from N
- Least number to be added to or subtracted from N to make it a Perfect Cube
- Check if number formed by joining two Numbers is Perfect Cube
- Perfect Cube factors of a Number
- C Program to check whether a number is a Perfect Cube or not
- Count all triplets whose sum is equal to a perfect cube
- 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
- Perfect Cube String
- Check whether N can be a Perfect Cube after adding or subtracting K
- Count of pairs in an Array whose sum is a 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 contribute@geeksforgeeks.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.