📜  最小的N位数字,是完美的四次幂

📅  最后修改于: 2021-05-04 08:55:45             🧑  作者: Mango

给定整数N ,任务是找到最小的N位数字,即完美的四次幂。
例子:

方法:可以观察到,对于N = 1,2,3,… ,该序列将继续像1,16,256,1296,10000,104976,1048576,…N项为pow( ceil((pow(pow(10,(n – 1)),1/4))),4)
下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
 
using namespace std;
 
// Function to return the smallest n-digit
// number which is a perfect fourth power
int cal(int n)
{
    double res = pow(ceil((pow(pow(10,
                          (n - 1)), 1 / 4) )), 4);
    return (int)res;
}
 
// Driver code
int main()
{
    int n = 1;
    cout << (cal(n));
}
 
// This code is contributed by Mohit Kumar


Java
// Java implementation of the approach
class GFG
{
 
// Function to return the smallest n-digit
// number which is a perfect fourth power
static int cal(int n)
{
    double res = Math.pow(Math.ceil((
                 Math.pow(Math.pow(10,
                (n - 1)), 1 / 4) )), 4);
    return (int)res;
}
 
// Driver code
public static void main(String[] args)
{
    int n = 1;
    System.out.println(cal(n));
}
}
 
// This code is contributed by CodeMech


Python3
# Python3 implementation of the approach
from math import *
 
# Function to return the smallest n-digit
# number which is a perfect fourth power
def cal(n):
    res = pow(ceil( (pow(pow(10, (n - 1)), 1 / 4) ) ), 4)
    return int(res)
 
# Driver code
n = 1
print(cal(n))


C#
// C# implementation of the approach
using System;
 
class GFG
{
 
// Function to return the smallest n-digit
// number which is a perfect fourth power
static int cal(int n)
{
    double res = Math.Pow(Math.Ceiling((
                 Math.Pow(Math.Pow(10,
                 (n - 1)), 1 / 4) )), 4);
    return (int)res;
}
 
// Driver code
public static void Main()
{
    int n = 1;
    Console.Write(cal(n));
}
}
 
// This code is contributed
// by Akanksha_Rai


Javascript


输出:
1