Example #1
0
def main():

    total = 0
    num_found = 0

    primes = pef.prime_sieve(999999)

    for i in primes[4:]:
        count = 0

        # determine amount to remove from each end
        for d in range(len(str(i))):

            # check if the shortened numbers are prime
            if pef.is_prime(int(str(i)[d::])) and pef.is_prime(
                    int(str(i)[0:d + 1])):
                count += 1

        # if removing from both ends gave expected result
        if count == len(str(i)):
            # print(str(i) + " IS A TRUNCATABLE PRIME")
            num_found += 1
            total += i

        # a known stopping condition is when we find 11 such primes
        if num_found == 11:
            break

    return total
Example #2
0
def main():

    i = 1
    while True:

        # use only odd numbers
        i += 2

        # if i is prime, then loop again
        if (pef.is_prime(i)):
            continue

        # set our variable to see if we make it through all combinations without
        # finding a matching set
        check = False

        # otherwise, see if we can find an exception
        for j in range(i, 0, -1):
            if (pef.is_prime(j)):

                k = 1
                # only need to check the answer if its going to be less than i
                while j + (2 * (k**2)) <= i:

                    if (i == j + (2 * (k**2))):
                        check = True

                    k += 1

        # check if we've found the appropriate number
        if check == False:
            return i
Example #3
0
def degree_prime_family(number, unidentifieds):

    ar = [
    ]  # define the array that will hold the various number we are looking through
    max_num_primes = 0  # define the variables for the max num of primes
    smallest_prime = 9999999  # define the smallest prime number that is looked for in return

    # turn the number in to an array
    for i in str(number):
        ar.append(str(i))

    # add in the declared number of unknown asterics
    for i in range(unidentifieds):
        ar.append('*')

    # loop through each permutation
    for perm in list(permutations(ar)):

        # the empty permutation with and *'s'
        perm_empty = ''.join(perm)

        num_primes = 0  # count the number of primes for that permutation
        first_prime = 0  # keep track of the first prime for a permutation
        found_prime = False  # check if we have found the first prime
        for j in range(10):

            # the completed permutation without and *'s'
            perm_filled = perm_empty.replace("*", str(j))

            # if the number begins with 0, we want to ignore it
            if perm_filled[0] == "0":
                continue

            # keep track of the first prime found in the permutation
            if pef.is_prime(int(perm_filled)) and found_prime == False:
                first_prime = int(perm_filled)
                found_prime = True

            if pef.is_prime(int(perm_filled)):
                num_primes += 1

                if num_primes >= max_num_primes:
                    smallest_prime = first_prime

            if max_num_primes < num_primes:
                max_num_primes = num_primes

    return max_num_primes, smallest_prime
Example #4
0
def main():

    number = 600851475143
    for i in range(int(math.sqrt(number)), 1, -1):
        if pef.is_prime(i) and number % i == 0:

        	return i
Example #5
0
def main():

    primes = pef.prime_sieve(50)
    group_size = 3
    prime_groups = combinations(primes, group_size)
    print(list(prime_groups))
    print(list(prime_groups)[1])

    print("Done making combinations...")

    for prime_group in list(prime_groups):

        # ignore 2 and 5, which would never create a possible solution
        if (2 in prime_group) or (5 in prime_group):
            continue

        prime_pairs = permutations(prime_group, 2)
        count = 0

        for prime_pair in list(prime_pairs):

            concat_prime_pair = int(str(prime_pair[0]) + str(prime_pair[1]))

            if pef.is_prime(concat_prime_pair):
                count += 1

        # 12 for group_size of 4 (4 pick 2 = 12)
        # 20 for group_size of 5 (5 pick 2 = 20)
        if count == 20:
            return sum(prime_group)
Example #6
0
def main():

    i = 1
    count = 1
    while count < 10001:
        i += 1
        if pef.is_prime(i):
            count += 1

    return i
Example #7
0
def main():

    # generate primes from 1000 - 9999
    primes = pef.prime_sieve(9999)[168:]

    for i in primes:
        jk_list = [int(x) for x in str(i)]  # list format of i
        jk_list_itts = list(itertools.permutations(jk_list))

        for j in jk_list_itts:
            # convert list of ints to int
            j = int(''.join(map(str, j)))

            for k in jk_list_itts:
                # convert list of ints to int
                k = int(''.join(map(str, k)))

                if abs(i - j) == abs(j - k) and \
                    i != j != k and i < j < k and \
                    pef.is_prime(j) and pef.is_prime(k) and \
                    i != 1487:

                    return ''.join(str(i) + str(j) + str(k))
Example #8
0
def number_unique_prime_factors(number, primes):
    not_completely_factored = True
    i = 0
    factors = []
    while not_completely_factored:

        if ( number / primes[i] == int(number / primes[i]) ):
            number = number / primes[i]
            factors.append(primes[i])
            i = -1

        if pef.is_prime(number):
            not_completely_factored = False
            factors.append(int(number))
        i += 1

    return len(set(factors))
Example #9
0
def main():

    maxn = 0
    answer = 0
    for a in range(-1000,1001):
        for b in range(-1000,1000):
            streak = 0
            for n in range(80):

                if pef.is_prime(n**2 + (n*a) + b):
                    streak += 1
                else:
                    break

                if maxn <= n:
                    maxn = n
                    answer = a * b

    return answer
Example #10
0
def main():
    maximum = 1000000
    primes = pef.prime_sieve(maximum)

    dic = {}
    dic['len'] = 0
    dic['num'] = 0

    for a in range(10):
        for b in range(a, maximum):
            inq = primes[a:b]  # array in question
            if sum(inq) > maximum:
                break

            if len(inq) > dic['len'] and sum(inq) > dic['num'] and \
                pef.is_prime(sum(inq)):
                dic['len'] = len(inq)
                dic['num'] = sum(inq)

    return dic['num']
Example #11
0
def main():
    maximum = 10**7
    prev_count = 0
    total = 0

    for i in range(maximum):
        # print(f'-- {i} --')

        curr_count = 1
        for j in range(1, math.ceil(math.sqrt(i))):
            if i % j == 0:
                curr_count += 1
                # print(j)

        if prev_count == curr_count:
            total += 1

        prev_count = curr_count

    print(total)

    return pef.is_prime(4)
Example #12
0
def main():

    total_primes = 0

    dist = 0
    cur = 1
    for i in range(100000):

        cur += dist

        # check the ratio of primes
        if i > 10:
            ratio = total_primes / i
            if ratio <= .1:
                return dist + 1

        # if ratio of primes
        if pef.is_prime(cur):
            total_primes += 1

        # increment the distance
        if i % 4 == 0:
            dist += 2