# N-th number which is both a square and a cube

Given a number n, find the n-th number which is both a square and a cube. First few such numbers are 1, 64, 729, …

**Examples :**

Input : 3 Output :729 729 is square of 27 and cube of 3. Input :5 Output :15625

The idea is simple, n-th such number is n^{6}

## C++

`// CPP program to find n-th number which is both ` `// square and cube. ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `int` `nthSquareCube(` `int` `n) ` `{ ` ` ` `return` `n*n*n*n*n*n; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 5; ` ` ` `cout << nthSquareCube(n); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find n-th number ` `// which is both square and cube. ` `class` `GFG { ` ` ` ` ` `static` `int` `nthSquareCube(` `int` `n) ` ` ` `{ ` ` ` `return` `n * n * n * n * n * n; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `int` `n = ` `5` `; ` ` ` ` ` `System.out.println(nthSquareCube(n)); ` ` ` `} ` `} ` ` ` `// This code is contributed by ` `// Smitha Dinesh Semwal ` |

*chevron_right*

*filter_none*

## Python 3

`# program to find n-th number ` `# which is both square and cube. ` ` ` `def` `nthSquareCube(n): ` ` ` ` ` `return` `n ` `*` `n ` `*` `n ` `*` `n ` `*` `n ` `*` `n ` ` ` ` ` `# Driver code ` `n ` `=` `5` `print` `(nthSquareCube(n)) ` `# This code is contributed by ` `# Smitha Dinesh Semwal ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find n-th number ` `// which is both square and cube. ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` ` ` `static` `int` `nthSquareCube(` `int` `n) ` ` ` `{ ` ` ` `return` `n * n * n * n * n * n; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `static` `public` `void` `Main () ` ` ` `{ ` ` ` `int` `n = 5; ` ` ` ` ` `Console.WriteLine(nthSquareCube(n)); ` ` ` `} ` `} ` ` ` `// This code is contributed by Ajit. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find n-th ` `// number which is both ` `// square and cube. ` ` ` `function` `nthSquareCube(` `$n` `) ` `{ ` ` ` `return` `$n` `* ` `$n` `* ` `$n` `* ` ` ` `$n` `* ` `$n` `* ` `$n` `; ` `} ` ` ` `// Driver code ` `$n` `= 5; ` `echo` `(nthSquareCube(` `$n` `)); ` ` ` `// This code is contributed by Ajit. ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

15625

## Recommended Posts:

- Count numbers upto N which are both perfect square and perfect cube
- Check if a number is perfect square without finding square root
- Centered cube number
- Perfect cube greater than a given number
- Largest perfect cube number in an Array
- Largest number in an array that is not a perfect cube
- Percentage increase in volume of the cube if a side of cube is increased by a given percentage
- Find the Largest Cube formed by Deleting minimum Digits from a number
- Find minimum number to be divided to make a number a perfect square
- Number of times the largest perfect square number can be subtracted from N
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Nth non-Square number
- Nth Square free number
- Demlo number (Square of 11...1)
- Centered Square 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 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.