The question website comes from the Chinese project Euler
Euler Once published a famous quadratic formula:
N2 +N+ 41
This formula can generate 40 prime numbers for consecutive numbers ranging from 0 to 39. However, whenNAt 40 o'clock, 402 + 40 + 41 = 40 (40 + 1) + 41 can be divisible by 41. WhenN41 at a time of 41, 41 + 41 + 41 can obviously be divisible by 41.
Using computers, people found an amazing formula:N2. 79N+ 1601. This formula is applicableN= 0 to 79 can generate 80 prime numbers. The coefficient of this formula, the product of 79 and 1601 is 126479.
Consider the quadratic formula in the following form:
N2 +An+B, Where |A| 1000 ,|B| 1000
Where |
N| Indicates
N.
For example, | 11 | = 11, | 4 | = 4
For continuousNGenerate the second formula of the maximum number of prime numbers to find the coefficient product of the formula.
**************************************** **************************************** ****
The optimization was not known at the first solution, and the computing took a lot of time.
The reason is that two layers-999 ~ 999 of the cycles, the cycle body needs to be calculated about 3.6 million times
In the Forum,Saif provides a filter for a B so that the cycle is about 1.6 million times.
N ^ 2 + An + B = n (n + a) + B = a prime number (we can see that B is a prime number; A is an odd number)
He said: because the result is a prime number, And when n = 0 is the expression equal to B, B must be a prime number (condition 1)
Analyze a now. When N is an odd number, only when a is an odd number is n (n + a) is an even number (the result may be a prime number)
When N is an even number, and only when a is an odd number, n (n + a) is an even number, and the result may be a prime number.