Exemplo n.º 1
0
def is_truncatable(n):
    str_n = str(n)
    if len(str_n) < 2:
        return False
    for i in range(1, len(str(n))):
        if not Prime.contains(int(str_n[:i])):
            return False
        if not Prime.contains(int(str_n[i:])):
            return False
    return True
Exemplo n.º 2
0
def satisfies_conjecture(n):
    root = 1
    while 2 * root**2 < n:
        if Prime.contains(n - 2 * root**2):
            return True
        root += 1
    return False
Exemplo n.º 3
0
def ans():
    num = 9
    while satisfies_conjecture(num):
        num += 2
        while Prime.contains(num):
            num += 2
    return num
Exemplo n.º 4
0
def ans():
    for prime in Prime.gen_nums():
        if prime < 120000:
            continue

        # Replace all combinations of digits
        list_ = list(str(prime))
        length = len(list_)
        for count in range(length):
            combs = combinations(range(length), count)
            for indices in combs:

                # Count the number of primes by replacing
                # the selected digits with some other digit
                generated_primes = set()
                for replacement in range(10):
                    copy = list_.copy()
                    for i in indices:
                        copy[i] = str(replacement)
                    number = int(''.join(copy))
                    if Prime.contains(number):
                        generated_primes.add(number)

                if 7 < len(generated_primes):
                    return min(generated_primes)
Exemplo n.º 5
0
def ans():
    lim = 1000
    largest = (None, None, 0)
    for a in range(-lim + 1, lim):
        for b in range(-lim, lim + 1):
            n = 0
            while Prime.contains(f(n, a, b)):
                n += 1
            if largest[2] < n:
                largest = (a, b, n)
    return largest[0] * largest[1]
Exemplo n.º 6
0
def ans():
    prime_list = list(Prime.gen_nums(4000))
    longest = (0, 0)
    for i in range(len(prime_list)):
        sum_ = 0
        for j in range(i, len(prime_list)):
            sum_ += prime_list[j]
            if 1000000 <= sum_:
                break
            if Prime.contains(sum_) and longest[1] < j - i + 1:
                longest = (sum_, j - i + 1)
    return longest[0]
Exemplo n.º 7
0
def ans():
    circular_primes = set([2])
    for p in Prime.gen_nums(1000000):
        if any(x in str(p) for x in '02468'):
            continue
        is_circular = True
        for i in range(len(str(p))):
            if not Prime.contains(int(str(p)[i:] + str(p)[:i])):
                is_circular = False
                break
        if is_circular:
            circular_primes.add(p)
    return len(circular_primes)
Exemplo n.º 8
0
def ans():
    diags = gen_diagonals()
    next(diags)
    i = 1
    prime_count = 0
    total_count = 1
    while True:
        for n in next(diags):
            if Prime.contains(n):
                prime_count += 1
            total_count += 1
        i += 2
        if prime_count / total_count < .1:
            break
    return i
Exemplo n.º 9
0
def ans():
    num = 600851475143
    end = int(sqrt(num)) + 1
    for i in reversed(range(2, end)):
        if num % i == 0 and Prime.contains(i):
            return i
Exemplo n.º 10
0
def compatible(one, two):
    return (
        Prime.contains(int(str(one) + str(two))) and
        Prime.contains(int(str(two) + str(one)))
    )