Find count of occurrences of each prime factor
Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; 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 . Count ; k ++ ) { while ( no > 1 && no % prime [ k ] == 0 ) { no /= prime [ k ] ; if ( mp . ContainsKey ( prime [ k ] ) ) mp [ prime [ k ] ] = prime [ k ] + 1 ; else mp . Add ( prime [ k ] , 1 ) ; } if ( no == 1 ) break ; } }