How to calculate smallest number with certain number of divisors?

前端 未结 9 1338
野性不改
野性不改 2020-12-29 07:51

From Project Euler problem 500

The number of divisors of 120 is 16. In fact 120 is the smallest number having 16 divisors.

Find the smalle

9条回答
  •  时光说笑
    2020-12-29 08:31

    The highest divisor any number has, other than itself, is the half of the number. For example, 120 has a max divisor of 60 other than itself. So, you can easily reduce the range from (n+1) to (n/2).

    More over, for a number to have m divisors, the number must be atleast ((m-1) * 2) following the above logic (-1 because the m th number is itself). For example, a number with 4 divisors has to be atleast 6. So, your search for n has a smaller range now.

    These two will reduce the runtime a little.

提交回复
热议问题