📜  第N个数字,既是正方形又是立方体

📅  最后修改于: 2021-05-04 20:49:41             🧑  作者: Mango

给定数字n,找到第n个既是正方形又是立方体的数字。前几个这样的数字是1、64、729等

例子 :

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

想法很简单,第n个这样的数字是n 6

C++
// C++ 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


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


Javascript


输出:
15625