Exemple #1
0
def sum_primes():
    prime_list = prime_sieve.sieve()
    counter = 0
    for prime in prime_list:
        if prime < 2000000:
            counter += prime
        else:
            return counter
def get_semiprimes(n):
    '''find all possible semiprime numbers up n'''

    primes = sieve(n)

    semiprimes = []

    for i in range(len(primes)):
        for j in range(i, len(primes)):
            semiprimes.append(primes[i] * primes[j])

    return semiprimes
from prime_sieve import sieve

first_10_primes = [2, 3, 5, 7, 11]
primes = sieve(11)[1]

assert primes == first_10_primes

lookup, ls = sieve(1000000)

# Verify that some numbers are primes or not
assert lookup[5] == True
assert lookup[31] == True
assert lookup[999983] == True
assert lookup[999987] == False
Exemple #4
0
from prime_sieve import sieve
from is_prime import is_prime

s, ps = sieve(1000000)

assert is_prime(31, s, ps) == True
assert is_prime(97, s, ps) == True
assert is_prime(100000000, s, ps) == False
assert is_prime(999983, s, ps) == True
Exemple #5
0
from prime_sieve import sieve

# convert list of ints back and forth to 6-bit encoded text
def octopus(int_list):
    temp = '8'.join(oct(n)[2:] for n in int_list)
    if len(temp) % 2:
        temp += '8'
    return ''.join(chr(32+(ord(a)-48)*9+(ord(b)-48))for a,b in zip(temp[::2], temp[1::2]))

deo=D=lambda _:[int(o,8)for o in''.join(f'{(ord(c)-32)//9}{(ord(c)-32)%9}'for c in _).split('8')if o]

s =  [*sieve(320)]
print(s)
o = octopus(s)
print(o)
d = deo(o)
print(d==s)
print(len(octopus(s)), len(' '.join(map(str,s))))