# 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
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

The idea is simple, n-th such number is n6

## C++

 `// CPP program to find n-th number which is both ` `// square and cube. ` `#include ` `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; ` `} `

## 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 `

## 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 `

## 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. `

## PHP

 ` `

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.

My Personal Notes arrow_drop_up good platform for learning

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.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.