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

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
- Percentage increase in volume of the cube if a side of cube is increased by a given percentage
- Previous perfect square and cube number smaller than number N
- Construct an Array of size N whose sum of cube of all elements is a perfect square
- Construct an Array such that cube sum of all element is a perfect square
- Divide array in two Subsets such that sum of square of sum of both subsets is maximum
- Find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d)
- Find all numbers up to N which are both Pentagonal and Hexagonal
- Count subsequences which contains both the maximum and minimum array element
- Largest right circular cylinder that can be inscribed within a cone which is in turn inscribed within a cube
- Largest right circular cone that can be inscribed within a sphere which is inscribed within a cube
- Largest sphere that can be inscribed within a cube which is in turn inscribed within a right circular cone
- Count of array elements which is smaller than both its adjacent elements
- Find smallest perfect square number A such that N + A is also a perfect square number
- Nth Square free number
- Nth non-Square number
- Find Nth number in a sequence which is not a multiple of a given number
- Minimum divisor of a number to make the number perfect cube
- Check if a number is perfect square without finding square root
- Smallest N digit number whose sum of square of digits is a Perfect Square

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.