text: Check if the given number is Ore number or not | Javascript program to check if the given number is Ore number ; Function that returns harmonic mean ; Note that this loop runs till square root ; If divisors are equal , store ' i ' ; else Otherwise store ' i ' and ' n / i ' both ; Utility function to calculate harmonic mean of the divisors ; Declare sum variables and initialize with zero . ; calculate denominator ; Calculate harmonic mean and return ; Function to check if a number is ore number ; Calculate Harmonic mean of divisors of n ; Check if harmonic mean is an integer or not ; Driver Code
code: var arr = [ ] ; function generateDivisors ( n ) { for ( var i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) arr . push ( i ) ; { arr . push ( i ) ; arr . push ( n / i ) ; } } } } function harmonicMean ( n ) { generateDivisors ( n ) ; var sum = 0.0 ; var len = arr . length ; for ( var i = 0 ; i < len ; i ++ ) sum = sum + ( n / arr [ i ] ) ; sum = ( sum / n ) ; return ( arr . length / sum ) ; } function isOreNumber ( n ) { var mean = harmonicMean ( n ) ; if ( mean - parseInt ( mean ) == 0 ) return true ; else return false ; } var n = 28 ; if ( isOreNumber ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;