Product of divisors of a number from a given list of its prime factors | Javascript Program to implement the above approach ; Function to calculate ( a ^ b ) % m ; Function to calculate and return the product of divisors ; Stores the frequencies of prime divisors ; Iterate over the prime divisors ; Update the product ; Update the count of divisors ; Driver Code
var MOD = 1000000007 ; function power ( a , b , m ) { a %= m ; var res = 1 ; while ( b > 0 ) { if ( b & 1 ) res = ( ( res % m ) * ( a % m ) ) % m ; a = ( ( a % m ) * ( a % m ) ) % m ; b >>= 1 ; } return res % m ; } function productOfDivisors ( p , n ) { var prime = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( prime . has ( p [ i ] ) ) prime . set ( p [ i ] , prime . get ( p [ i ] ) + 1 ) else prime . set ( p [ i ] , 1 ) } var product = 1 , d = 1 ; prime . forEach ( ( value , key ) => { var val = power ( key , ( value ) * ( value + 1 ) / 2 , MOD ) ; product = ( power ( product , value + 1 , MOD ) * power ( val , d , MOD ) ) % MOD ; d = ( d * ( value + 1 ) ) % ( MOD - 1 ) ; } ) ; return product ; } var arr = [ 11 , 11 ] ; var n = arr . length ; document . write ( productOfDivisors ( arr , n ) ) ;