文章目錄

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

Quadratic primes

Euler discovered the remarkable quadratic formula:

n² + n + 41

It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 402 + 40 + 41 = 40(40 + 1) + 41 is divisible by 41, and certainly when n = 41, 41² + 41 + 41 is clearly divisible by 41.

The incredible formula n² -79n + 1601 was discovered, which produces 80 primes for the consecutive values n = 0 to 79. The product of the coefficients, -79 and 1601, is -126479.

Considering quadratics of the form:

n² + an + b, where |a| <1000 and |b| <1000
where |n| is the modulus/absolute value of n
e.g. |11| = 11 and |-4| = 4
Find the product of the coefficients, a and b, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n = 0.

二项式素数

欧拉发现著名的二项式公式:

n² + n + 41

当n从0到39时,这个公式可以产生40个连续的素数。然而,当n = 40时, 402 + 40 + 41 = 40(40 + 1) + 41可以被41整除,毫无疑问的,当n = 41时,41² + 41 + 41可以被41整除

另一个惊人的公式n² − 79n + 1601 被发现,这个公式当n = 0到79时可以产生80个连续的素数。两个系数-79和1601的乘积为-126479.

考虑如下的二项式形式

n² + an + b, 且|a| <1000 , |b| <1000

这里 |n| 是 n的绝对值
e.g. |11| = 11 and |-4| = 4

求对于这个二项式表达式,从n = 0开始,连续产生最多素数的系数a和b的乘积。

解法:

这题没什么好说的,先用筛法生成一个素数判断表,之后就是遍历了。

打赏作者

文章目錄