コード例 #1
0
ファイル: allEulerSols.py プロジェクト: hayleyguillou/eul
def eul58():
    """See web for spiral pattern.
     If this process is continued, what is the side length of the square spiral for which the ratio of primes
     along both diagonals first falls below n = 10%?"""
    num_diag = 5
    num_primes = 3
    curr = 9
    adder = 4

    while num_primes/num_diag > 0.1:
        for j in range(4):
            curr += adder
            num_diag += 1
            if eul.prime(curr):
                num_primes += 1
        adder += 2

    return adder - 1
コード例 #2
0
ファイル: allEulerSols.py プロジェクト: hayleyguillou/eul
def eul27():
    """Find the product of the coefficients, a and b, for the quadratic expression (n^2+n+41)
    that produces the maximum number of primes for consecutive values of n, starting with n=0."""

    max_n = -1
    max_prod = (0, 0)
    y = 1000

    for a in range(-y, y+1):
        for b in range(-y, y+1):
            n = 0
            prod = n**2 + (a*n) + b
            while eul.prime(prod):
                n += 1
                prod = n**2 + (a*n) + b
            if n > max_n:
                max_n = n
                max_prod = a * b
    return max_prod
コード例 #3
0
ファイル: allEulerSols.py プロジェクト: hayleyguillou/eul
def eul41():
    """What is the largest n-digit pandigital prime that exists?"""
    for p in range(7654321, 1, -2):
        if eul.pandigital(p, 7) and eul.prime(p):
            return p
コード例 #4
0
ファイル: eul060.py プロジェクト: hayleyguillou/eul
def check(m, n):
    return prime(append_ints(m, n)) and prime(append_ints(n, m))