Exemple #1
0
def truncatable(number):
    string = str(number)
    for i in range(1, len(string)):
        if isprime(int(string[i:])) == False:
            return False
    for i in range(1, len(string)):
        if isprime(int(string[:i])) == False:
            return False
    return True
def main():
    for i in prime_list:
        difference = 1
        while (i + difference * 2) < 10000:
            difference += 1
            if isprime(i + difference):
                if ispermutation(i, i + difference):
                    if isprime(i + difference * 2):
                        if ispermutation(i, i + difference * 2):
                            print(i, i + difference, i + difference * 2)
Exemple #3
0
def main():
    list = []
    for i in range(2, 1000000):
        if isprime(i):
            if remove(i):
                list.append(i)
    print(len(list))
def main2():  ##快很多
    odd = 3
    while True:
        found = False
        odd += 2
        root = 1
        if not isprime(odd):
            while found == False:
                remainder = odd - 2 * (root**2)
                if isprime(remainder):
                    print('odd:', odd, 'prime:', remainder, 'square:', root**2)
                    found = True
                    break
                root += 1
                if (root**2) * 2 > odd:
                    print(odd)
                    return True
def main1():
    odd = 7
    while True:
        odd += 2
        found = False
        i = 2
        if not isprime(odd):
            while found == False:
                if isprime(i):
                    remain = (odd - i) / 2
                    if issquare(remain):
                        found = True
                        print('odd:', odd, 'prime:', i, 'square:', remain)
                i += 1
                if i > odd - 1:
                    print(odd)
                    return True
Exemple #6
0
def remove(number):
    rotation = number
    string = str(number)
    '''for i in string:
        if i in ['2', '4', '5', '6', '8','0']:
            return False'''
    for i in range(len(str(rotation))):
        rotation = (rotation % 10) * (10 ** (len(str(rotation)) - 1)) + rotation // 10
        if not isprime(rotation):
            return False
    return True
def number_of_prime_factors(number):
    count = 0
    for i in prime_list:
        if i**2 > number:
            break
        if number % i == 0:
            count += 1
            while number % i == 0:
                number = number / i
    if number == 1:
        return count
    if isprime(number):
        count += 1
        return count
def main():
    for i in range(100000, 1000000):
        last_digit = i % 10
        if last_digit in [1, 3, 7, 9]:
            for model_index in range(6):
                count = 0
                non_count = 0
                for change_to in range(1, 10):
                    test = transform(model1(model_index), i, change_to)
                    if isprime(test):
                        count += 1
                    else: non_count += 1
                    if non_count > 1:
                        break
                if count == 8:
                    print(i)
                    for change_to in range(1, 3):
                        if isprime(transform(model1(model_index), i, change_to)):
                            print(transform(model1(model_index), i, change_to))
                            break
                    return True
            for model_index in range(4):
                count = 0
                non_count = 0
                for change_to in range(0, 10):
                    if isprime(transform(model2(model_index), i, change_to)):
                        count += 1
                    else:non_count += 1
                    if non_count > 2:
                        break
                if count == 8:
                    print(i)
                    if isprime(transform(model2(model_index), i, change_to)):
                        print(transform(model2(model_index), i, change_to))
                        break
                    return True
def gererate_prime(upper_bound):
    a = []
    for i in range(2, upper_bound):
        if isprime(i):
            a.append(i)
    return a
Exemple #10
0
def all_prime(chain):
    return all(
        isprime(int(str(p[0]) + str(p[1])))
        for p in iter.permutations(chain, 2))
Exemple #11
0
from uint_prime import isprime
import time


def truncatable(number):
    string = str(number)
    for i in range(1, len(string)):
        if isprime(int(string[i:])) == False:
            return False
    for i in range(1, len(string)):
        if isprime(int(string[:i])) == False:
            return False
    return True


kaishi = time.time()
start = 11
count = 0
list = []
while count < 11:
    start += 1
    if isprime(start):
        if truncatable(start):
            count += 1
            list.append(start)
            print(count)
            print(list)
jieshu = time.time()
print(sum(list))
print(jieshu - kaishi)
def generate_prime(lowerbound, upperbound):
    a = []
    for i in range(lowerbound, upperbound):
        if isprime(i):
            a.append(i)
    return a
Exemple #13
0
from uint_prime import isprime
import time
start = time.time()

def pandigital(number):
    l = list(str(number))
    l.sort()
    list1 = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
    if l == list1[:len(l)]:
        return True


for i in range(10000000, 2, -1):
    if pandigital(i):
      if isprime(i):
            print(i)
            break

end = time.time()
print(end - start)


def prime_list(upper_bound):
    a = []
    for i in range(1, upper_bound):
        if isprime(i):
            a.append(i)
    return a
def longest(list):
    if isprime(sum(list)):
        return len(list)
    else:
        return longest(list[:len(list) - 1])