def p_range(lower_inclusive, upper_exclusive):
    'Primes in the range'
    for p in primes():
        if p >= upper_exclusive: break
        if p >= lower_inclusive: yield p
from __future__ import print_function
from prime_decomposition import primes
from itertools import islice


def p_range(lower_inclusive, upper_exclusive):
    'Primes in the range'
    for p in primes():
        if p >= upper_exclusive: break
        if p >= lower_inclusive: yield p

if __name__ == '__main__':
    print('The first twenty primes:\n  ', list(islice(primes(),20)))
    print('The primes between 100 and 150:\n  ', list(p_range(100, 150)))
    print('The ''number'' of primes between 7,700 and 8,000:\n  ', len(list(p_range(7700, 8000))))
    print('The 10,000th prime:\n  ', next(islice(primes(),10000-1, 10000)))
Esempio n. 3
0
def p_range(lower_inclusive, upper_exclusive):
    'Primes in the range'
    for p in primes():
        if p >= upper_exclusive: break
        if p >= lower_inclusive: yield p
Esempio n. 4
0
    Problem 146 at ProjectEuler
'''

import math
from prime_decomposition import primes
from collections import deque

def is_same(deq, target):
    return [ deq[i] - deq[i-1] for i in range(1, len(deq))] == target

prime_deq = deque([0],maxlen=6)
TARGET_SEQUENCE = [2, 4, 2, 4, 14]
last = 0
total = 0

for p in primes():
    prime_deq.append(p)
    if p - last == 14:
        if is_same(prime_deq, TARGET_SEQUENCE):
            n = math.sqrt(prime_deq.popleft()-1)

            if n > 1000000:
                break

            if n % 1 == 0:
                total += n
                print n
    last = p

print total
Esempio n. 5
0
from __future__ import print_function
from prime_decomposition import primes
from itertools import islice
 
 
def p_range(lower_inclusive, upper_exclusive):
    'Primes in the range'
    for p in primes():
        if p >= upper_exclusive: break
        if p >= lower_inclusive: yield p
 
if __name__ == '__main__':
    print('The first twenty primes:\n  ', list(islice(primes(),20)))
    print('The primes between 100 and 150:\n  ', list(p_range(100, 150)))
    print('The ''number'' of primes between 7,700 and 8,000:\n  ', len(list(p_range(7700, 8000))))
    print('The 10,000th prime:\n  ', next(islice(primes(),10000-1, 10000)))