📜  N除数的几何平均值的整数部分

📅  最后修改于: 2021-04-23 18:02:18             🧑  作者: Mango

给定一个整数N ,任务是找到N个除数的几何平均值的整数部分。几何均值是一种特殊的平均值,其中我们将数字相乘,然后取平方根(对于两个数字),立方根(对于三个数字),依此类推。

方法:可以观察到,将形成一个N值为1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,…的级数N术语是⌊√n⌋。
下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
using namespace std;
 
// Function to return the integer
// part of the geometric mean
// of the divisors of n
int geometricMean(int n)
{
    return sqrt(n);
}
 
// Driver code
int main()
{
    int n = 16;
 
    cout << geometricMean(n);
 
    return 0;
}


Java
// Java implementation of the approach
class GFG
{
 
// Function to return the integer
// part of the geometric mean
// of the divisors of n
static int geometricMean(int n)
{
    return (int) Math.sqrt(n);
}
 
// Driver code
public static void main(String []args)
{
    int n = 16;
    System.out.println(geometricMean(n));
}
}
 
// This code is contributed by Rajput-Ji


Python3
# Python3 implementation of the approach
from math import sqrt
 
# Function to return the integer
# part of the geometric mean
# of the divisors of n
def geometricMean(n) :
 
    return int(sqrt(n));
 
# Driver code
if __name__ == "__main__" :
 
    n = 16;
 
    print(geometricMean(n));
 
# This code is contributed by AnkitRai01


C#
// C# implementation of the approach
using System;   
 
class GFG
{
  
// Function to return the integer
// part of the geometric mean
// of the divisors of n
static int geometricMean(int n)
{
    return (int) Math.Sqrt(n);
}
  
// Driver code
public static void Main(String []args)
{
    int n = 16;
    Console.WriteLine(geometricMean(n));
}
}
 
// This code is contributed by PrinciRaj1992


Javascript


输出:
4