Beispiel #1
0
def main():

    upper = 100000

    max_consecutives = 0

    max_consecutives_prime = 0

    count = 1

    sum_primes = [2]

    for i in range(3, upper, 2):
        if is_prime(i):
            count += 1

            for index in range(0, len(sum_primes) - max_consecutives):
                sum_primes[index] += i
                temp = sum_primes[index]

                if temp > upper:
                    continue

                if is_prime(temp) and max_consecutives < count - index:
                    max_consecutives = count - index
                    max_consecutives_prime = temp

            sum_primes.append(i)

    print("{}-{}".format(max_consecutives_prime, max_consecutives))

    return 0
Beispiel #2
0
def count_spiral_primes(k):
    count = 0

    bottom_right = k*k

    bottom_left = bottom_right - k + 1

    top_left = bottom_left - k + 1

    top_right = top_left - k + 1

    
    return is_prime(bottom_left) + is_prime(top_left) + is_prime(top_right)
Beispiel #3
0
def prime_pairs(primes):
    pairs = findsubsets(primes, 2)

    for pair in pairs:

        pair0 = concatenating(pair[0], pair[1])
        pair1 = concatenating(pair[1], pair[0])

        if not is_prime(pair0) or not is_prime(pair1):

            return False

    return True
Beispiel #4
0
def main():

    index = 11
    primes = [{3}, {5}, {7}]

    set_primes = 5

    while True:
        if is_prime(index):
            if {index} not in primes:
                for e in primes:
                    if prime_pair_number_with_list(index, e):
                        temp = {index} | e
                        if len(temp) == set_primes:
                            print(temp)

                            sum60 = 0

                            for e in temp:
                                sum += e

                            print(sum60)

                            return 0
                        primes.append(temp)

                primes.append({index})

        index += 2

    return 0
Beispiel #5
0
def main():
    blacklist = set()

    for i in range(1001, 9999, 2):
        if is_prime(i):
            
            temp = number_permutations(i)

            p_i = sorted([i for i in temp if is_prime(i) and len(str(i)) == 4])

            if i not in blacklist:
                
                if len(p_i) >= 3:
                    for e in findsubsets(p_i,3):
                        if is_arithmetic(e):
                            print(''.join(str(j) for j in e))

            blacklist |= {i for i in p_i}

    return 0
Beispiel #6
0
def get_prime(n):
    index = 1

    count = 1  # already count 2 as prime

    if n < 1:
        return None
    if n == 1:
        return 2

    while count < n:
        index += 2
        if is_prime(index):
            count += 1

    return index
Beispiel #7
0
def main():
    upper = 2000000

    sum10 = 2

    index = 3

    while index < upper:
        if is_prime(index):
            sum10 += index

        index += 2

    print(sum10)

    return 0
Beispiel #8
0
def main():

    index = 11

    start_sequence = 0  #store the first of sequences, also result

    num = 8

    while True:
        slices = [i for i in range(0, len(str(index)) - 1)]

        for j in range(1, len(str(index))):
            mask = findsubsets(slices,
                               j)  # get all the ways to replace digits with *

            for e in mask:
                temp = str(index)

                count = 0

                sequences = []

                for i in range(0, 10):
                    for k in e:
                        temp = temp[:k] + str(i) + temp[k + 1:]

                    if temp[0] == '0':
                        continue  # ignore when replace first digit with 0

                    if (is_prime(int(temp))):
                        count += 1
                        sequences.append(temp)

                    if count == num:
                        print("Found: {}, e={}".format(str(index), e))

                        print(sequences)

                        print(sequences[0])
                        return 0

        index += 2

    return 0
Beispiel #9
0
def main():

    index = 9
    primes = {2, 3, 5, 7}

    while True:
        if is_prime(index):
            primes |= {index}
        else:
            count =  len(primes)
            for e in primes:
                if (index - e)%2 == 0 and is_square_number((index-e)/2):
                    print("{}={} + 2x{}^2".format(index, e, int(math.sqrt((index -e)/2))))
                    break
                else:
                    count -= 1
            
            if count == 0:
                print("Found: {}".format(index))
                break
            
        index += 2 
  
    return 0
Beispiel #10
0
def prime_factors(p):
    factors = {}

    index = 2

    temp = p

    while index < p:
        if mymodule.is_prime(temp):
            factors[temp] = 1
            break

        if temp % index == 0:
            if index in factors:
                factors[index] += 1
            else:
                factors[index] = 1
            temp = int(temp / index)

            continue

        index += 1

    return factors
Beispiel #11
0
def prime_pair(p, q):
    pair0 = concatenating(p, q)
    pair1 = concatenating(q, p)

    return is_prime(pair0) and is_prime(pair1)
import mymodule

print("73 is Prime:", mymodule.is_prime(73))
print("73 Number of Factors:", mymodule.num_factors(73))