示例#1
0
def get_more_primes():
    global working_combos, all_primes
    all_primes = get_prime_numbers_until(10000)
    all_primes.remove(2)
    all_primes.remove(5)
    for cur_prime in all_primes:
        for prime in list(working_combos.keys()):
            left = int(str(prime) + str(cur_prime))
            right = int(str(cur_prime) + str(prime))
            if is_prime(left) and is_prime(right):
                working_combos[prime].add(cur_prime)
                working_combos[cur_prime].add(prime)
        working_combos[cur_prime] = set()
示例#2
0
def second_try():
    max_consecutive = 0
    primes = get_prime_numbers_until(1000000)
    last_prime = primes[len(primes) - 1]
    for index, prime in enumerate(primes):
        if prime * max_consecutive > last_prime:
            break

        prime_sum = 0
        index_offset = 0
        while prime_sum < last_prime:
            prime_sum += primes[index + index_offset]
            if index_offset > max_consecutive and prime_sum in primes:
                max_consecutive = index_offset
                max_consecutive_prime = prime_sum
            index_offset += 1
    return max_consecutive, max_consecutive_prime
示例#3
0
def first_try():
    primes = get_prime_numbers_until(1000000)
    max_consecutive_prime = 0
    max_consecutive = 2
    for prime in reversed(primes):
        starting_primes = [p for p in primes if p < prime / max_consecutive]
        for index, sp in enumerate(starting_primes):
            prime_sum = 0
            index_offset = 0
            while prime_sum < prime:
                prime_sum += primes[index + index_offset]
                index_offset += 1
            if prime_sum == prime and index_offset > max_consecutive:
                max_consecutive = index_offset
                max_consecutive_prime = prime
                print(prime, index_offset, len(starting_primes))
                break
            elif prime_sum > prime and index_offset < max_consecutive:
                break
    return max_consecutive, max_consecutive_prime
示例#4
0
from helpers import get_prime_numbers_until

print(sum(get_prime_numbers_until(2 * (10**6))))

print(get_prime_numbers_until(100))
示例#5
0
from helpers import get_prime_numbers_until

number = 600851475143
root = number ** 0.5
prime_numbers = get_prime_numbers_until(int(root))
result = 0
for prime_number in reversed(prime_numbers):
    if number % prime_number == 0:
        result = prime_number
        break

# for num in reversed(range(2, int(number ** .5))):
#     if number % num == 0:
#         if is_prime(num):
#             result = num
#             break
print(result)
示例#6
0
from helpers import is_prime, get_prime_numbers_until

highest_combo = (0, 0, 0)
primes = get_prime_numbers_until(1001)

for a in range(-999, 1000):
    for b in primes:
        n = 0
        while True:
            number = n**2 + a * n + b
            if number < 2 or not is_prime(number):
                n -= 1
                if n > highest_combo[2]:
                    print('new high', a, b, n)
                    highest_combo = (a, b, n)
                break
            n += 1

print(highest_combo[0] * highest_combo[1])
示例#7
0
from helpers import get_prime_numbers_until

target = 50 * 10 ** 6
primes_1 = get_prime_numbers_until(int(target ** (1/2)) + 1)
primes_2 = get_prime_numbers_until(int(target ** (1/3)) + 1)
primes_3 = get_prime_numbers_until(int(target ** (1/4)) + 1)
numbers = set()
itters = 0
for prime_1 in primes_1:
    prime_1_square = prime_1 ** 2
    for prime_2 in primes_2:
        prime_2_cube = prime_2 ** 3
        if prime_1_square + prime_2_cube > target:
            primes_2 = [prime for prime in primes_2 if prime < prime_2]

        for prime_3 in primes_3:
            prime_3_fourth = prime_3 ** 4

            if prime_1_square + prime_3_fourth > target:
                primes_3 = [prime for prime in primes_3 if prime < prime_3]
            num = prime_1_square + prime_2_cube + prime_3_fourth
            if num < target:
                numbers.add(num)
            itters += 1

print(itters)
print(len(numbers))