Traverse from 1 to Math . Sqrt ( N ) if i divides N , increment i and N / i in map
for ( int i = 1 ; i <= ( Math . Sqrt ( n ) ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) { if ( mp . ContainsKey ( i ) ) mp [ i ] = mp [ i ] + 1 ; else mp . Add ( i , 1 ) ; } else { if ( mp . ContainsKey ( i ) ) mp [ i ] = mp [ i ] + 1 ; else mp . Add ( i , 1 ) ; if ( mp . ContainsKey ( n / i ) ) mp [ n / i ] = mp [ n / i ] + 1 ; else mp . Add ( n / i , 1 ) ; } } } }