Find counts of occurrences of each prime factor
var j ; var mp = new Map ( ) ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < prime . length ; j ++ ) { while ( arr [ i ] > 1 && arr [ i ] % prime [ j ] == 0 ) { arr [ i ] /= prime [ j ] ; if ( mp . has ( prime [ j ] ) ) mp . set ( prime [ j ] , mp . get ( prime [ j ] ) + 1 ) ; else mp . set ( prime [ j ] , 1 ) ; } } if ( arr [ i ] != 1 ) { if ( mp . has ( arr [ i ] ) ) mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; else mp . set ( arr [ i ] , 1 ) ; } }