Product of proper divisors of a number for Q queries | Javascript implementation of the above approach ; Function to precompute the product of proper divisors of a number at it 's corresponding index ; Returning the pre - computed values ; Driver code
mod = 1000000007 ans = Array ( 100002 ) . fill ( 1 ) function preCompute ( ) { for ( var i = 2 ; i <= 100000 / 2 ; i ++ ) { for ( var j = 2 * i ; j <= 100000 ; j += i ) { ans [ j ] = ( ans [ j ] * i ) % mod ; } } } function productOfProperDivi ( num ) { return ans [ num ] ; } preCompute ( ) ; var queries = 5 ; var a = [ 4 , 6 , 8 , 16 , 36 ] ; for ( var i = 0 ; i < queries ; i ++ ) { document . write ( productOfProperDivi ( a [ i ] ) + " " ) ; }