Find count of occurrences of each prime factor
HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; int row_no = 0 ; long max_factor = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { int no = arr [ i ] [ j ] ; for ( int k = 0 ; k < prime . size ( ) ; k ++ ) { while ( no > 1 && no % prime . get ( k ) == 0 ) { no /= prime . get ( k ) ; if ( mp . containsKey ( prime . get ( k ) ) ) mp . put ( prime . get ( k ) , prime . get ( k ) + 1 ) ; else mp . put ( prime . get ( k ) , 1 ) ; } if ( no == 1 ) break ; } }