从项目欧拉问题500
120除数的数是16。事实上120具有16的除数的最小数字。
The number of divisors of 120 is 16. In fact 120 is the smallest number having 16 divisors.
查找最小的数与2 ** 500500除数。给你的答案模500500507。
Find the smallest number with 2**500500 divisors. Give your answer modulo 500500507.
这是很简单的计算n的约数,例如。在Python LEN([我为我的range(1,N + 1)如果n%我== 0])
。这是O(n)。
It's simple enough to count the divisors of n, eg. in Python len([i for i in range(1,n+1) if n % i == 0])
. This is O(n).
我试图蛮力搜索,发现最小的数字与32除数是840,但它的多为上述问题的速度太慢。从不平等 count_divisors(N)其中。= N
,这个数字将是巨大的。
I tried brute force search and found the smallest number with 32 divisors is 840, but it's much too slow for the problem above. From the inequality count_divisors(n) <= n
, the number is going to be massive.
你怎么看?有任何想法吗?如何计算与一定数量的约数最小的数字?
What do you think? Any ideas? How to calculate smallest number with certain number of divisors?
修改:我不认为这是一个重复。这个问题是比较具体的,它涉及某一类的多的较大的数字。 href="http://stackoverflow.com/questions/8861994">其他问题一般询问 = 0。现在的问题是 - 为了获得 X ,是它更好地提高权力2(即增加一个 1 ),或使用7(即取 4 = 1,而不是 4 = 0) ?那么,它的简单检查,2 * 3 * 5 * 7> 2 3 * 3 * 5 = 120,这就是为什么120的答案在这种情况下。
where ai >= 0. The question is now - in order to get minimum value of x
, is it better to increase the powers of 2 (i.e., increment a1), or to use 7 (i.e. take a4=1 instead of a4=0)? Well, it's simple to check, 2*3*5*7 > 23 * 3 * 5 = 120, that's why the 120 is answer in this case.
如何推广这种做法?您应该创建分堆,你就会把素数的权力,照顾的分频器的数量达到指定值。如果16,这分堆将包含数字2,3,5,7,2 2 3 2 2 4 等。 为什么?由于16 = 2 4 ,所以每个(一个我 +1)有16分,也就是说,它必须是2,当您添加新的电源功率每次,就应该增加左侧(即变量 D(X)
)由2的幂,因为你的最终目标是找到最小的数与2 500500 约数。
How to generalize this approach? You should create min-heap where you'll put the powers of primes, taking care that the number of divisors reaches the specified value. In case of 16, this min-heap would contain numbers 2, 3, 5, 7, 22, 32, 24 etc. Why? Because 16 = 24, so each of (ai+1) has to divide 16, i.e. it has to be power of 2. Every time when you add new power, it should increase the left hand side (i.e., the variable d(x)
) by power of 2, since your final goal is to find the smallest number with 2500500 divisors.
HTH。
相关推荐
最新文章