欧拉计划 #50,素数不正确?
Project Euler #50, prime sums not correct?
The prime 41, can be written as the sum of six consecutive primes:
41 = 2 + 3 + 5 + 7 + 11 + 13 This is the longest sum of consecutive
primes that adds to a prime below one-hundred.
The longest sum of consecutive primes below one-thousand that adds to
a prime, contains 21 terms, and is equal to 953.
Which prime, below one-million, can be written as the sum of the most
consecutive primes?
我在这个例子中使用了 Racket(scheme 的一种方言),但这应该与语言无关。在这个问题中,它指出前 21 个连续质数的总和是 953。所以,我去测试一下(我已经为这个问题编写了我的代码并且它工作不正确)。
> (define primes (filter prime? (range 2 10000)))
> (apply + (take primes 6)) ; This is 41: Good so far!
> ; This is where it gets odd.
> (apply + (take primes 21)) ; This is 712. And, after further experimentation, there is amount of summed primes that is 953.
> (apply + (take primes 23)) ; This is 874.
> (apply + (take primes 24)) ; This is 963.
我是否遗漏了这个问题?
你看错问题了。总和也必须是质数,而 963 不是(例如 107 * 9)。
Euler #50 求连续素数之和,不一定要从第一个素数开始。所示示例以第一个素数开始的事实是偶然的(尽管获胜序列以 small 素数开始并非偶然)。
953 = 7 + 11 + 13 + 17 + 19 + 23 + 29
+ 31 + 37 + 41 + 43 + 47 + 53 + 59
+ 61 + 67 + 71 + 73 + 79 + 83 + 89
这是 21 个术语。问题描述没有错误 - 术语 'first' 没有出现在文本中的任何地方。
The prime 41, can be written as the sum of six consecutive primes:
41 = 2 + 3 + 5 + 7 + 11 + 13 This is the longest sum of consecutive primes that adds to a prime below one-hundred.
The longest sum of consecutive primes below one-thousand that adds to a prime, contains 21 terms, and is equal to 953.
Which prime, below one-million, can be written as the sum of the most consecutive primes?
我在这个例子中使用了 Racket(scheme 的一种方言),但这应该与语言无关。在这个问题中,它指出前 21 个连续质数的总和是 953。所以,我去测试一下(我已经为这个问题编写了我的代码并且它工作不正确)。
> (define primes (filter prime? (range 2 10000)))
> (apply + (take primes 6)) ; This is 41: Good so far!
> ; This is where it gets odd.
> (apply + (take primes 21)) ; This is 712. And, after further experimentation, there is amount of summed primes that is 953.
> (apply + (take primes 23)) ; This is 874.
> (apply + (take primes 24)) ; This is 963.
我是否遗漏了这个问题?
你看错问题了。总和也必须是质数,而 963 不是(例如 107 * 9)。
Euler #50 求连续素数之和,不一定要从第一个素数开始。所示示例以第一个素数开始的事实是偶然的(尽管获胜序列以 small 素数开始并非偶然)。
953 = 7 + 11 + 13 + 17 + 19 + 23 + 29
+ 31 + 37 + 41 + 43 + 47 + 53 + 59
+ 61 + 67 + 71 + 73 + 79 + 83 + 89
这是 21 个术语。问题描述没有错误 - 术语 'first' 没有出现在文本中的任何地方。