示例#1
0
def list_to_prime(x):
    res = []
    for i in range(1, x + 1):
        if is_prime(i):
            res.append(i)
    for i in range(1, len(res)):
        p = int(math.log(x, res[i]))
        res[i] **= p

    return sorted(res)
示例#2
0
def find_max_decimal_cycle_mt(d: int):
    nb_threads = _getThreads()
    producer_queue = Queue(nb_threads - 1)
    temp_queue = Queue()
    res_queue = Queue()

    consumers = [
        Process(target=consuming, args=(producer_queue, temp_queue))
        for _ in range(nb_threads - 1)
    ]

    max_computer = Process(target=compute_max, args=(temp_queue, res_queue))

    for p in consumers + [max_computer]:
        p.start()

    for i in range(3, d, 2):
        # Discard not prime numbers
        if not is_prime(i):
            continue

        producer_queue.put(i)

    # Signal that it's over for consumers
    for _ in range(len(consumers)):
        producer_queue.put(None)

    # Wait for them
    for p in consumers:
        p.join()

    # Then signal to the max_compute that it's over
    temp_queue.put((None, None))

    # Wait for it
    max_computer.join()

    # And then print the results
    n, lambda_ = res_queue.get()

    # Print the result with a pretty print
    print(f"Number found: {n}. Length: {lambda_}")
    test_with_one_number(n)
示例#3
0
def find_max_decimal_cycle(d: int):
    n = 0
    max_decimals = 0
    for i in range(3, d, 2):
        # Discard not prime numbers
        if not is_prime(i):
            continue

        l, mu = get_decimal_with_cycle(i)
        if mu is None:
            # No cycle
            continue

        lambda_ = len(l) - mu

        # Find a cycle, compare its length
        if lambda_ > max_decimals:
            max_decimals = lambda_
            n = i

    # Print the result with a pretty print
    print(f"Number found: {n}. Length: {max_decimals}")
    test_with_one_number(n)
示例#4
0
import math
from utils.util import is_prime

n = 10001
prime_list = []
i = 2
while len(prime_list) < n:
    if is_prime(i):
        prime_list.append(i)
    i += 1

print(prime_list[-1])
示例#5
0
def find_next_prime(x):
    while True:
        x += 1
        if is_prime(x):
            return x
示例#6
0
# So b is positive and a prime number
# I don't have proof yet, but I have the impression that a
# should be negative.
# Let's try that

from utils.util import get_primes, is_prime


def f(n, a, b):
    return n * n + a * n + b


max_n = 0
res_a = 0
res_b = 0

for b in get_primes(1000):
    for a in range(-1000, 1):
        n = 1
        value = f(n, a, b)
        while value > 0 and is_prime(value):
            n += 1
            value = f(n, a, b)

        if n - 1 > max_n:
            max_n = n - 1
            res_a = a
            res_b = b

print(f"Found a={res_a} and b={res_b}. Yield {max_n} consecutive primes")