Efficient Algorithm to determine highly composited numbers
As in many cases, read the problem carefully first. The problem asks for all numbers that have more divisors than any small numbers. Nobody asks you to determine the number of divisors of lots of numbers. 

First write down the formula how to calculate the number of divisors of n, given its factorisation into prime numbers. Then figure out rules that say what kinds of prime factors a highly composite number might have. Quite obviously a highly composite number must be a product $2^a·3^b·5^c·7^d...$ where a ≥ b ≥ c ≥ d and so on. That's because if for example a &lt; b, then $2^b·3^a$ would be smaller than $2^a·3^b$ but have the same number of prime factors. 

That's just the start of it, but this should already help you to find highly composite numbers up to n a lot, lot faster than O (n).