コード例 #1
0
def is_truncatable_prime(num):
    divisor = 1
    for i_unused in range(10, num):
        divisor *= 10
        if not is_prime(num % divisor) or not is_prime(num // divisor):
            return False
        if len(str(divisor)) == len(str(num)):
            break
    return True
コード例 #2
0
def get_truncatable_primes():
    truncatable_primes, prime_num = [], 23
    while len(truncatable_primes) < 11:
        if is_prime(prime_num) and is_truncatable_prime(prime_num):
            truncatable_primes.append(prime_num)
        prime_num += 2
    return truncatable_primes
コード例 #3
0
def get_largest_pandigital_prime():
    num_str = '123456789'
    while True:
        all_nums = sorted(get_permutations(num_str), reverse=True)
        for num in all_nums:
            if is_prime(int(num)):
                return num
        num_str = num_str[:-1]
        if num_str == '': break
コード例 #4
0
def quadratic_primes(num):
    max_val = 0
    for b in get_prime_list(num):
        for a in range(-1 * (num - 1), num, 2):
            n = 1
            while is_prime(abs(n * n + a * n + b)):
                n += 1
            if n > max_val:
                co_efficients, max_val = (a, b), n
    return co_efficients[0] * co_efficients[1]
コード例 #5
0
def get_prime_list(max_cap):
    prime_nums = []
    for num in range(2, max_cap + 1):
        if is_prime(num):
            prime_nums.append(num)
    return prime_nums