Beispiel #1
0
def answer():
    # (a, b, <consecutive prime count>)
    max_count = (0, 0, 0)
    
    def quadradic_calc(n, a, b):
        return n**2 + a*n + b
    
    def consecutive_prime_count(a, b):
        n = 0
        while True:
            if not prime_ba[quadradic_calc(n, a, b)]:
                return n
            n += 1
    
    primes.init_prime_bitarray(20000)
    prime_ba = primes.primes_ba
    primes.bitarray_to_list()
    prime_list = [p for p in primes.primes if p < 1000]
    neg_prime_list = [-1 * p for p in prime_list]
    
    for a in neg_prime_list:
        for b in prime_list:
            count = consecutive_prime_count(a, b)
            if(count > max_count[2]):
                max_count = (a, b, count)
    
    return max_count[0] * max_count[1]
Beispiel #2
0
def answer():
    truncatable = []
    primes.init_prime_bitarray(1000000)

    for pr in (i for i, isprime in enumerate(primes.primes_ba) if isprime):
        if pr < 11:
            continue
        if len(truncatable) == 11:
            break
        if is_truncatable(pr):
            truncatable.append(pr)

    return sum(truncatable)
Beispiel #3
0
import primes as p
from math import log10
p.init_prime_bitarray(1000000)
p.bitarray_to_list()
primes = set(p.primes)

def get_rotations(n):
    rotations = set([n])
    l = int(log10(n))
    for x in range(l):
        n = (n%10)*10**(l) + n//10
        rotations.add(n)
    return rotations

def answer():
    return sum(1 for a in primes if get_rotations(a).issubset(primes))
    
if __name__=='__main__':
    print(answer())
Beispiel #4
0
import primes

primes.init_prime_bitarray(100)
primes.bitarray_to_list()
ba = primes.primes_ba
print(ba)
print(primes.primes)

# Rotate list: a.insert(0,a.pop())
# Rotate a number: (n%10)*10**(int(math.log10(n))) + n/10
'''Rotate a digit.
l = int(math.log10(n))
a = [n]
for i in range(l):
     n = (n%10)*10**(l) + n/10
     a.append(n)
return a
'''