예제 #1
0
def fleft(n):
    while len(n) >= 1:
        if isprime(int(n)):
            return fleft(n[1:])
        else:
            return False
    return True
예제 #2
0
def fright(n):
    while len(n) >= 1:
        if isprime(int(n)):
            return fright(n[:-1])
        else:
            return False
    return True
예제 #3
0
def func_recur(liste):
    global aa,bb
    while len(liste) > 1:
        sum = 0
        counter = 0
        a,b = 0,0
        for i in liste:
            sum += i
            counter += 1
            if primenumbers.isprime(sum):
                a = sum
                b = counter
        if b > bb:
            aa,bb = a,b
        else: pass
        a,b,sum,counter = 0,0,0,0
        return func_recur(liste[1:])
    return None
예제 #4
0
        else:
            return False
    return True


def fright(n):
    while len(n) >= 1:
        if isprime(int(n)):
            return fright(n[:-1])
        else:
            return False
    return True


total = 0
counter = 0
number = 13
while counter != 11:
    if isprime(number):
        if bool(fleft(str(number))):
            if bool(fright(str(number))):
                total += number
                counter += 1

    number += 1

print(total)

elapsed = time.time() - starting
print(elapsed)
예제 #5
0
import primenumbers
import time
beginning = time.time()

primes = [x for x in range(3947) if primenumbers.isprime(x)]

aa = 0
bb = 0
def func_recur(liste):
    global aa,bb
    while len(liste) > 1:
        sum = 0
        counter = 0
        a,b = 0,0
        for i in liste:
            sum += i
            counter += 1
            if primenumbers.isprime(sum):
                a = sum
                b = counter
        if b > bb:
            aa,bb = a,b
        else: pass
        a,b,sum,counter = 0,0,0,0
        return func_recur(liste[1:])
    return None

func_recur(primes)
print(aa,bb)
print(func_recur(primes))
예제 #6
0
import primenumbers as pn
n = 0
primes = []
for i in range(100, 1000 + 1):
    if pn.isprime(i) is True:
        n += 1
        primes.append(i)

print("100부터 1000까지의 소수는 {}개".format(n))
print("100부터 1000까지의 소수:", primes)