Пример #1
0
def consecutiveprimes(a, b):
    n = 0
    while 1:
        if isPrime(n**2 + a * n + b):
            n += 1
        else:
            return n
Пример #2
0
def run():
    i = 1
    while 1:
        n = 2 * i + 1
        if isPrime(n) or checker(n):
            i += 1
            continue
        return n
Пример #3
0
def tructprime(n):

	if isPrime(n):

		m = n % 10 ** int(log(n,10))
		n = n//10
		while n != 0:
			if isPrime(n):
				n = n//10
			else:
				return False

		while m > 10:		
			if isPrime(m):
				m = m % 10 ** int(log(m,10))
			else:
				return False

		return(isPrime(m))
		
	else:
		return False
Пример #4
0
from projecteuler import isPrime

counter = 1
n = 3
current = 2

while(counter < 10001):
    if isPrime(n):
        counter += 1
        current = n
        n += 2
    else:
        n += 2

print(current)
Пример #5
0
from projecteuler import isPrime
from itertools import permutations

primes = []

for i in range(1009, 9974):
    if isPrime(i):
        primes.append(i)

for i in primes:
    perms = list(permutations(str(i)))
    perm_primes = []
    for j in perms:
        k = int(j[0]) * 1000 + int(j[1]) * 100 + int(j[2]) * 10 + int(j[3])
        if k in primes:
            perm_primes.append(k)

    if len(perm_primes) >= 3:
        for l in perm_primes:
            if (l + 3330 in perm_primes) & (l + 6660 in perm_primes):
                print(l, l + 3330, l + 6660)
Пример #6
0
from projecteuler import isPrime
from functools import reduce

prime_sum = [2]

for i in range(3, 1000000):
    if isPrime(i):
        prime_sum.append(prime_sum[-1] + i)

most_consec = 21

for i in range(most_consec, len(prime_sum)):
    for j in range(i - (most_consec + 1), 0, -1):
        if (prime_sum[i] - prime_sum[j] > 1000000):
            break
        if isPrime(prime_sum[i] - prime_sum[j]):
            most_consec = i - j
            result = prime_sum[i] - prime_sum[j]

print(result)
Пример #7
0
#this took a long time to run, very nonoptimal
from math import sqrt
from projecteuler import isPrime

primes = [x for x in range(2, 1000000) if isPrime(x)]
non_circular_p = primes[:]

for i in primes:

    l_i = list(str(i))

    if len([x for x in l_i if int(x) % 2 == 0 or int(x) == 5]) > 0:
        continue
    else:
        no_good = 0
        for j in range(len(l_i) - 1):
            #rotate to next number
            l_i.append(l_i.pop(0))

            temp = int(''.join(l_i))

            if temp not in primes:
                no_good = 1
                break

        if no_good == 0:
            non_circular_p.pop(non_circular_p.index(i))

non_circular_p.pop(non_circular_p.index(2))
non_circular_p.pop(non_circular_p.index(5))
Пример #8
0
def checker(n):
    for i in range(1, int(sqrt(n / 2)) + 1):
        if isPrime(n - 2 * i * i):
            return True
    return False