Skip to content
Related Articles

Related Articles

Improve Article
Integer part of the geometric mean of the divisors of N
  • Last Updated : 06 Apr, 2021

Given an integer N, the task is to find the integer part of the geometric mean of the divisors of N. The Geometric Mean is a special type of average where we multiply the numbers together and then take a square root (for two numbers), cube root (for three numbers), and so on.
 

Examples: 
Input: N = 4 
Output:
Divisors of 4 are 1, 2 and 4 
Geometric mean = (1 * 2 * 4)(1/3) = 8(1/3) = 2
Input: N = 16 
Output:
Divisors of 16 are 1, 2, 4, 8 and 16 
Geometric mean = (1 * 2 * 4 * 8 * 16)(1/5) = 1024(1/5) = 4 
 

 

 

Approach: It cane be observed that a series will be formed for the values of N as 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, ….. whose Nth term is āŒŠāˆšnāŒ‹.
Below is the implementation of the above approach: 
 



C++




// C++ implementation of the approach
#include <bits/stdc++.h>
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




<script>
 
// Javascript implementation of the approach
 
// Function to return the integer
// part of the geometric mean
// of the divisors of n
function geometricMean(n)
{
    return Math.sqrt(n);
}
 
// Driver code
var n = 16;
document.write(geometricMean(n));
 
</script>
Output: 
4

 

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.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

In case you wish to attend live classes with industry experts, please refer Geeks Classes Live




My Personal Notes arrow_drop_up
Recommended Articles
Page :