嵇爾的吐槽

#没事画轮子的嵇尔不定期的(W)碎(E)碎(B)念(B)和(L)吐(O)槽(G)

Problem 27 Quadratic primes 2016-10-10 12:05:00

Euler discovered the remarkable quadratic formula:

It turns out that the formula will produce 40 primes for the consecutive integer values . However, when is divisible by 41, and certainly when is clearly divisible by 41.

The incredible formula was discovered, which produces 80 primes for the consecutive values . The product of the coefficients, −79 and 1601, is −126479.

Considering quadratics of the form:

, where and

where is the modulus/absolute value of

e.g. and

Find the product of the coefficients, and , for the quadratic expression that produces the maximum number of primes for consecutive values of , starting with .


第27题 二次“素数生成”多项式”

欧拉发现了这个著名的二次多项式:

对于连续的整数n,,这个二次多项式生成了40个素数。然而,当时,能够被41整除,同时显然当时,也能被41整除。

随后,另一个神奇的多项式被发现了,对于连续的整数n,,它生成了80个素数。这个多项式的系数-79和1601的乘积为-126479。

考虑以下形式的二次多项式:

, 满足

其中的模或绝对值 例如 以及

这其中存在某个二次多项式能够对从0开始尽可能多的连续整数都生成素数,求其系数a和b的乘积。


import math


def is_Prime(number):
    if number < 2:
        return False
    for x in range(2, int(math.sqrt(number)) + 1):
        if number % x == 0:
            return False
    return True

result_count = 0
result_a = -1000
result_b = -1000
for a in range(-1000, 1000):
    for b in range(1, 1000):
        count = 0
        for x in range(0, 1001):
            if is_Prime(x * x + a * x + b):
                count += 1
            else:
                if count > result_count:
                    result_count = count
                    result_a = a
                    result_b = b
                    print "a = %s, b = %s, count = %s" % (a, b, count)
                break
print
print "product = %s" % (result_a * result_b)

感想:

  1. 暴力破解很无耻
  2. 该break时候就应该break
评论共