Find count of occurrences of each prime factor
let mp = new Map ( ) ; let row_no = 0 ; let max_factor = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { let no = arr [ i ] [ j ] ; for ( let k = 0 ; k < prime . length ; k ++ ) { while ( no > 1 && no % prime [ k ] == 0 ) { no /= prime [ k ] ; if ( mp . has ( prime [ k ] ) ) { mp . set ( prime [ k ] , mp . get ( prime [ k ] ) + 1 ) } else { mp . set ( prime [ k ] , 1 ) } } if ( no == 1 ) break ; } }