Exemplo n.º 1
0
 def compute_nb_blocks(self, size, sizeOfBlocks):
     # if the size is divided per 128
     if size % sizeOfBlocks == 0 and not mymath.is_prime(
             size // sizeOfBlocks):
         self.nbBlocks = size // sizeOfBlocks
     else:
         if size % sizeOfBlocks != 0 and mymath.is_prime(size //
                                                         sizeOfBlocks + 1):
             self.nbBlocks = size // sizeOfBlocks + 2
         else:
             self.nbBlocks = size // sizeOfBlocks + 1
def generate_right_truncatable_primes(n):
    if not is_prime(int(n)):
        return

    right_truncatable_primes.append(int(n))
    for d in right_append_allowed:
        new_n = n + d
        generate_right_truncatable_primes(new_n)
def is_left_truncatable_prime(n):
    num = str(n)
    l = len(num)
    for i in range(l):
        if not is_prime(int(num[i:])):
            return False

    return True
def prime_perm_arithmetic_seq(comb: tuple):
    prime_perm = set()
    for perm in permutations(comb):
        if perm[0] == '0':
            continue

        nump = int("".join(perm))
        if is_prime(nump):
            prime_perm.add(nump)

    length = len(prime_perm)
    if length < 3:
        return

    prime_perm = list(prime_perm)
    for i in range(length):
        for j in range(i + 1, length):
            avg = (prime_perm[i] + prime_perm[j])
            if avg % 2 == 1:
                continue
            avg //= 2
            if avg in prime_perm:
                print(prime_perm[i], avg, prime_perm[j])
Exemplo n.º 5
0
def is_circular_prime(n):
    for i in range(len(str(n))):
        if not is_prime(n):
            return False
        n = rotate(n)
    return True
Exemplo n.º 6
0
'''
sum(1,9) = 45, so pandigital with 9 digit not possible
sum(1,8) = 36, so pandigital with 8 digits not possible
sum(1,7) = 28, possible

'''
from itertools import permutations
from mymath import is_prime

max_num = -1

for p in permutations("7654321"):
    # converts permutaion touple to string to int
    n = int("".join(p))
    if is_prime(n):
        print("Largest Pandigital Prime ", n)
        break

# ans 7652413
Exemplo n.º 7
0
from mymath import is_prime

n = 1
primes = 0
while True:
    diag = [(2 * n - 1)**2 + 2 * n, (2 * n - 1)**2 + 4 * n,
            (2 * n + 1)**2 - 2 * n]
    for num in diag:
        if is_prime(num):
            primes += 1

    proportion = primes / (4 * n + 1) * 100
    if proportion < 10:
        print(n)
        break
    n += 1

print("Side length", 2 * n + 1)
Exemplo n.º 8
0
from mymath import is_prime

maxstreak = 0
for a in range(-999, 1000):
    for b in range(-999, 1000):
        n = 0
        while is_prime(n * n + a * n + b):
            n += 1
        if maxstreak < n:
            maxstreak, maxa, maxb = n, a, b

print(maxa * maxb)
def prime_run(a, b):
    n = 0
    while is_prime(quadratic(a, b, n)):
        n += 1

    return n