文章目錄

原题链接http://projecteuler.net/problem=50

Consecutive prime sum

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?

连续素数的和
素数41,可以写成6个连续素数的和:
41 = 2 + 3 + 5 + 7 + 11 + 13
这是100以下最长的连续素数的和等于一个素数
1000以下最长的连续素数的和,包含21个数,等于953
求1 000 000​以下能写成最长连续素数的和的素数


解法:
不懂得数学方法,只好暴力了,先求出1000 000以下素数,之后双重循环。太暴力了,竟然用了18分钟,看来还是得想办法改进。果然还是有方法的,想办法生成一个三角形,最底层是1000 000以下素数,上一层是连续两个素数之和,再上一层是连续三个素数之和,。。最后一层就是所有素数之和,从上往下找,第一个小于1000000的素数就是答案。实际过程中,可以不用从最顶上开始找,可以从第一个大于1000000那一行开始往下找,然后由这一行的数生成下一行,继续找。

打赏作者

文章目錄