The prime number sequence starts with: `2,3,5,7,11,13,17,19...`. Notice that `2` is in position `one`. 

`3` occupies position `two`, which is a prime-numbered position. Similarly, `5`, `11` and `17` also occupy prime-numbered positions. We shall call primes such as `3,5,11,17` dominant primes because they occupy prime-numbered positions in the prime number sequence. Let's call this `listA`. 

As you can see from listA, for the prime range `range(0,10)`, there are `only two` dominant primes (`3` and `5`) and the sum of these primes is: `3 + 5 = 8`. 

Similarly, as shown in listA, in the `range (6,20)`, the dominant primes in this range are `11` and `17`, with a sum of `28`.

Given a `range (a,b)`, what is the sum of dominant primes within that range? Note that  `a <= range <= b` and `b` will not exceed `500000`.

Good luck!

If you like this Kata, you will enjoy:

[Simple Prime Streaming](https://www.codewars.com/kata/5a908da30025e995880000e3)

[Sum of prime-indexed elements](https://www.codewars.com/kata/59f38b033640ce9fc700015b)

[Divisor harmony](https://www.codewars.com/kata/59bf97cd4f98a8b1cd00007e)

Difficulty: introductory

Starter code:

def solve(a,b):
	

Solutions:
n = 500000
sieve, PRIMES = [0]*(n//2+1), [0,2]
for i in range(3, n+1, 2):
    if not sieve[i//2]:
        PRIMES.append(i)
        for j in range(i**2, n+1, i*2): sieve[j//2] = 1

DOMINANTS = []
for p in PRIMES:
    if p >= len(PRIMES): break
    DOMINANTS.append(PRIMES[p])

def solve(a,b):
    return sum(p for p in DOMINANTS if a <= p <= b)

from itertools import compress, takewhile
import numpy as np

s = np.ones(500000)
s[:2] = s[4::2] = 0
for i in range(3, int(len(s)**0.5)+1, 2):
    if s[i]:
        s[i*i::i] = 0
primes = list(compress(range(len(s)), s))
xs = [primes[i-1] for i in takewhile(lambda x: x < len(primes), primes)]

def solve(a,b):
    return sum(xs[np.searchsorted(xs, a):np.searchsorted(xs, b, side='right')])

n = 10 ** 6
dominant, primes, sieve = [], set(), [0, 0] + [1] * (n-2)
for k in range(n):
    if sieve[k]:
        primes.add(k)
        sieve[k*k::k] = ((n - k*k - 1) // k + 1) * [0]
        if len(primes) in primes: dominant.append(k)

from bisect import bisect
solve = lambda a, b: sum(dominant[bisect(dominant, a-1): bisect(dominant, b)])

primes = [3]
primes_set = {2, 3}
dominant = [3]

for n in range(5, 500000, 2):
    for p in primes:
        if p*p > n:
            primes.append(n)
            primes_set.add(n)
            if len(primes_set) in primes_set:
                dominant.append(n)
            break
        if n%p == 0:
            break

def solve(a, b):
    return sum(p for p in dominant if a <= p <= b)

def list_simple_num(a):
    lst = list(range(a + 1))
    lst[1] = 0
    for l in lst:
        if l != 0:
            for j in range(2 * l, len(lst), l):
                lst[j] = 0
    return lst
        
def solve(a,b):
    lst  = tuple(filter(bool, list_simple_num(b)))
    ind  = list_simple_num(len(lst))[1:]
    return sum(lst for ind,lst in zip(ind,lst) if ind != 0 and lst > a)

import itertools 
compress = itertools.compress 
def primeSieve(n):
    if n < 2:
        return []
    r = [False,True] * (n//2)+[True]
    r[1],r[2]=False, True
    for i in range(3,int(1 + n**0.5),2):
        if r[i]:
            r[i*i::2*i] = [False] * ((n+2*i-1-i*i)//(2*i))
    r = list(compress(list(range(len(r))),r))
    if r[-1] %2 == 0:
        r.pop() 
    return r
primes = primeSieve(500000)

dicti = dict() 
for i in range(len(primes)): 
    dicti[primes[i]] = i+1
    
primeSet = frozenset(primes) 

def solve(a,b): 
    sum = 0
    for i in range(a,b+1): 
        if i in primeSet: 
            if dicti[i] in primeSet: 
                sum += i
    return sum




a = [False, False]+[True]*500000; p = []
for (i, isprime) in enumerate(a):
    if isprime:
        p.append(i)
        for n in range(i*i, 500001, i): a[n] = False
dp = [p[i-1] for i in p if i-1<len(p)]
def solve(a,b):
    return sum(n for n in dp if a<=n<=b)

def solve(a, b):
    primes = [False,2] + [x for x in range(3, b+1, 2) if all(x % d for d in range(3, int(x**.5+1), 2))]
    dom_pos = [primes[x] for x in primes if x < len(primes)]
    return sum(x for x in dom_pos if a <= x <= b)

def solve(a,b):

    
    range_n = b+1 
    is_prime = [True] * range_n
    primes = [0]
    result = 0
    for i in range (2, range_n):
        if is_prime[i]:
            primes += i,
            for j in range (2*i, range_n, i):
                is_prime[j] = False

    for i in range (2, len(primes)):
        if primes[i] >= a and is_prime[i]: result += primes[i]
            
    return result