Traverse from 1 to sqrt ( N ) if i divides N , increment i and N / i in map
for ( var i = 1 ; i <= parseInt ( Math . sqrt ( n ) ) ; i ++ ) { if ( n % i == 0 ) { if ( parseInt ( n / i ) == i ) { if ( mp . has ( i ) ) mp . set ( i , mp . get ( i ) + 1 ) else mp . set ( i , 1 ) } else { if ( mp . has ( i ) ) mp . set ( i , mp . get ( i ) + 1 ) else mp . set ( i , 1 ) if ( mp . has ( parseInt ( n / i ) ) ) mp . set ( parseInt ( n / i ) , mp . get ( parseInt ( n / i ) ) + 1 ) else mp . set ( parseInt ( n / i ) , 1 ) } } } return mp ; }