Find counts of occurrences of each prime factor
Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < prime . Count ; j ++ ) { while ( arr [ i ] > 1 && arr [ i ] % prime [ j ] == 0 ) { arr [ i ] /= prime [ j ] ; if ( mp . ContainsKey ( prime [ j ] ) ) { mp [ prime [ j ] ] ++ ; } else { mp . Add ( prime [ j ] , 1 ) ; } } } if ( arr [ i ] != 1 ) { if ( mp . ContainsKey ( arr [ i ] ) ) { mp [ arr [ i ] ] ++ ; } else { mp . Add ( arr [ i ] , 1 ) ; } } }