N-th number which is both a square and a cube
Last Updated :
20 Feb, 2023
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 n6
C++
#include <bits/stdc++.h>
using namespace std;
int nthSquareCube( int n)
{
return n*n*n*n*n*n;
}
int main()
{
int n = 5;
cout << nthSquareCube(n);
return 0;
}
|
Java
import java.io.*;
public class GFG {
static int nthSquareCube( int n)
{
return n * n * n * n * n * n;
}
public static void main(String[] args)
{
int n = 5 ;
System.out.println(nthSquareCube(n));
}
}
|
Python3
def nthSquareCube(n):
return n * n * n * n * n * n
n = 5
print (nthSquareCube(n))
|
C#
using System;
class GFG
{
static int nthSquareCube( int n)
{
return n * n * n * n * n * n;
}
static public void Main ()
{
int n = 5;
Console.WriteLine(nthSquareCube(n));
}
}
|
PHP
<?php
function nthSquareCube( $n )
{
return $n * $n * $n *
$n * $n * $n ;
}
$n = 5;
echo (nthSquareCube( $n ));
?>
|
Javascript
<script>
function nthSquareCube(n)
{
return n * n * n * n * n * n;
}
let n = 5;
document.write(nthSquareCube(n));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...