Exemplo n.º 1
0
def compute():
    maximal = 0
    total = 0

    # Construct lists for a and b
    zeroth = functions.prime_sieve(1000)
    first = [-i for i in zeroth]
    first = first + zeroth

    # Construct list for checking if prime
    temp = functions.prime_sieve(3 * 1000 * 1000)
    checking = 3 * 1000000 * [False]
    for i in temp:
        checking[i] = True

    for a in first:
        for b in zeroth:

            maximum = 0
            n = 0

            while checking[n * n + a * n + b]:
                n += 1
                maximum += 1

            if maximum > maximal:
                maximal = maximum
                total = a * b

    return str(total)
def compute():
    total = 0
    
    primes = functions.prime_sieve(LIMIT)
    
    check = [False]*LIMIT
    
    for i in primes:
        string = str(i)
        
        length = len(string)
        
        summation = i
        
        for j in range(length-1):
            
            if not check[int(string[j+1:])]:
                summation = 0
                break
            
            if not check[int(string[:j-1])]:
                summation = 0
                break
        
        total += summation
        
        
            
    return str(total)
Exemplo n.º 3
0
def compute():
    total = 0
    
    primes = functions.prime_sieve(UPPER_BOUND)
    check = functions.prime_check(UPPER_BOUND)
    
    maximum = 0
    max_prime = 0
    
    for i in range(len(primes)):
        
        consecutive = 1
        
        temp_sum = primes[i]
        
        for j in range(i+1,len(primes)):
            
            temp_sum += primes[j]
            consecutive += 1
            
            if temp_sum >= UPPER_BOUND:
                break
            
            if check[temp_sum] and consecutive > maximum:
                maximum = consecutive
                max_prime = temp_sum
            
        
            
    return str(max_prime)
def compute():
    total = 0

    primes = functions.prime_sieve(LIMIT)

    check = [False] * LIMIT

    for i in primes:
        check[i] = True

    for i in primes:
        string = str(i)

        length = len(string)

        score = 1

        for i in range(length):
            temp = ""
            for j in range(length):
                temp += string[(i + j) % length]

            if not check[int(temp)]:
                score = 0
                break

        total += score

    return str(total)
def compute():
    total = 0

    sieve = functions.prime_sieve(int(10**4))

    primes = [False] * int(10**4)

    for i in sieve:
        primes[i] = True

    for i in sieve:

        if i > 10**4 / 3:
            break

        if i > 1000:
            for j in range(1, int(10**4 / 3)):

                if primes[i + j] and primes[i + 2 * j]:

                    p1 = str(i)
                    p2 = str(i + j)
                    p3 = str(i + 2 * j)

                    if sorted(p1) == sorted(p2) and sorted(p2) == sorted(p3):

                        if i is not 1487:
                            total = p1 + p2 + p3

    return str(total)
def compute():
    index = 10001

    n = functions.prime_upper_bound(index)

    primes = functions.prime_sieve(n)

    return str(primes[index - 1])
Exemplo n.º 7
0
def compute():
    total = 0

    primes = functions.prime_sieve(NUMBER)

    total = sum(primes)

    return str(total)
Exemplo n.º 8
0
def compute():
    total = 0
    
    sieve = functions.prime_sieve(UPPER_BOUND)
    
    numbers = UPPER_BOUND * [0]
    
    for i in sieve:
        
        for j in range(0,int(math.sqrt(UPPER_BOUND)/2)):
            if i + 2*j*j >= UPPER_BOUND:
                break
            
            numbers[i+2*j*j] += 1
    
    for i in range(UPPER_BOUND):
        if numbers[i] == 0 and i%2 == 1 and i > 5:
            total = i
            break
            
    return str(total)
Exemplo n.º 9
0
from functions import isPrime, prime_sieve


def truncatable(p):
    s = str(p)
    while p > 0:
        if p > 2 and p % 2 == 0:
            return False
        p //= 10

    if any(not isPrime(int(s[i:])) for i in range(0, len(s))):
        return False

    if any(not isPrime(int(s[:i])) for i in range(len(s), 0, -1)):
        return False

    return True


out = []
primes = prime_sieve(1000000)
for i in primes:
    if i < 10:
        continue
    if truncatable(i):
        out.append(i)
print(sum(out))
Exemplo n.º 10
0
    if len(gpf(n)) == digits:
        #print(n)
        nums.append(n)
        if len(nums) > digits-1:
            print("Length:", len(nums), n)
            break
        n+=1
    else:
        del nums[:]
        n += 14-(n%10)


print(nums)
'''
base_primes = [2]
primes = set(functions.prime_sieve(10, []))-set(base_primes)

def sieve(prime_factors):
    flags = [True for i in range(1,1001)]
    for i in prime_factors:
        l = len(flags)//i
        #print(l)
        flags[i::i] = [False]*(l+l%2-1) #Sets all multiples to false
    return list(flags)

for p in primes:
    p_factors = base_primes + [p]
    rel_pr = sieve(p_factors)
    print(rel_pr)
    for i in range(len(rel_pr)-2):
        if rel_pr[i] and rel_pr[i+1]:
Exemplo n.º 11
0

if __name__ == '__main__':
    import time
    import functions
    import sys

    start = time.time()

    triangle_limit = 13*10**3
    max_limit = 10*4
    max_triangle = (triangle_limit * (triangle_limit+1))/2
    triangle_sqrt = int(max_triangle**0.5)+1
    

    primes = functions.prime_sieve(max_triangle/2)
#    print(primes)
    print '{} primes, max prime: {}'.format(len(primes), max(primes))
    print '{: } kbytes in primes'.format(sys.getsizeof(primes)/1000)
    prime_time = time.time() - start
    print '{0:.3f} ms for prime numbers'.format(1000*prime_time)
    #print("prime time: ", repr(prime_time))
    a = 0
    for i in xrange(1, triangle_limit):
        #a is the triangle number
        a += i
        
        num_of_divisors = primefactoring(a, primes)
 
        #print '{0} - {1}, divisors: {2}'.format(i, a, num_of_divisors)
        
Exemplo n.º 12
0
# UNSOLVED

import functions as f

primes = f.prime_sieve(10000, [])
pblts = []

for prime in primes:
    subs = [prime]
    for i in range(0, primes.index(prime)):
        if str(primes[i]) in str(prime):
            subs.append(primes[i])
    if len(subs) >= 3:
        pblts.append(subs)

count = {i: 0 for i in primes}
for set in pblts:
    for i in range(1, len(set)):
        count[set[i]] += 1

for i in count.keys():
    if count[i] >= 4:
        print(i, count[i])
Exemplo n.º 13
0
# -*- coding: UTF-8 -*-

import functions
import time

start = time.time()

limit = 2*(10**6)
primes = functions.prime_sieve(limit)
prime_sum = sum(primes)

end = time.time() - start

print("sum of primes: " + repr(prime_sum))
print("time: " + repr(end))

Exemplo n.º 14
0
from functions import phi, prime_sieve

x = 1
primes = prime_sieve(10000, [])
i = 0
while x * primes[i] <= 1000000:
    x = x * primes[i]
    i += 1
print(x)
Exemplo n.º 15
0
from functions import phi, prime_sieve

check = 15499 / 94744
"""
for i in range(2,94744):
    if i%1000 == 0:
        print i/1000, "%"
    if 1.0*phi(i)/(i-1) < check:
        print(i)
        break
"""
primes = prime_sieve(50000, output=[])

val = 1
for p in range(2, 50000):
    if val > 1000000:
        print "Exceeded limit"
        break
    #print(val)
    val *= p
    if 1.0 * phi(val) / (val - 1) < 0.4:
        print(val)
        break