(n, ith=1)
Return the ith prime greater than n.

        i must be an integer.

        Notes
        =====

        Potential primes are located at 6*j +/- 1. This
        property is used during searching.

        >>> from sympy import nextprime
        >>> [(i, nextprime(i)) for i in range(10, 15)]
        [(10, 11), (11, 13), (12, 13), (13, 17), (14, 17)]
        >>> nextprime(2, ith=2) # the 2nd prime after 2
        5

        See Also
        ========

        prevprime : Return the largest prime smaller than n
        primerange : Generate all primes in a given range
Return the ith prime greater than n.
Return the ith prime greater than n .
def nextprime(n, ith=1):
    """ Return the ith prime greater than n.

        i must be an integer.

        Notes
        =====

        Potential primes are located at 6*j +/- 1. This
        property is used during searching.

        >>> from sympy import nextprime
        >>> [(i, nextprime(i)) for i in range(10, 15)]
        [(10, 11), (11, 13), (12, 13), (13, 17), (14, 17)]
        >>> nextprime(2, ith=2) # the 2nd prime after 2
        5

        See Also
        ========

        prevprime : Return the largest prime smaller than n
        primerange : Generate all primes in a given range

    """
    n = int(n)
    i = as_int(ith)
    if i > 1:
        pr = n
        j = 1
        while 1:
            pr = nextprime(pr)
            j += 1
            if j > i:
                break
        return pr

    if n < 2:
        return 2
    if n < 7:
        return {2: 3, 3: 5, 4: 5, 5: 7, 6: 7}[n]
    nn = 6*(n//6)
    if nn == n:
        n += 1
        if isprime(n):
            return n
        n += 4
    elif n - nn == 5:
        n += 2
        if isprime(n):
            return n
        n += 4
    else:
        n = nn + 5
    while 1:
        if isprime(n):
            return n
        n += 2
        if isprime(n):
            return n
        n += 4
def nextprime ( n , ith = 1 ) : n = int ( n ) i = as_int ( ith ) if i > 1 : pr = n j = 1 while 1 : pr = nextprime ( pr ) j += 1 if j > i : break return pr if n < 2 : return 2 if n < 7 : return { 2 : 3 , 3 : 5 , 4 : 5 , 5 : 7 , 6 : 7 } [ n ] nn = 6 * ( n // 6 ) if nn == n : n += 1 if isprime ( n ) : return n n += 4 elif n - nn == 5 : n += 2 if isprime ( n ) : return n n += 4 else : n = nn + 5 while 1 : if isprime ( n ) : return n n += 2 if isprime ( n ) : return n n += 4