def ith_prime(i):
    """
    gets prime(i)
    input: number
    return: number
    """
    global primes, interval
    while i >= len(primes):
        a = ((primes[-1] + 2) // 6) * 6 - 1
        b = a + interval
        c = a + 2
        d = b + 2
        try:
            primes.extend(filter(isprime, xrange(a, b, 6)))
            primes.extend(filter(isprime, xrange(c, d, 6)))
            primes = sorted(list(set(primes)))
            mpp = open(fn, 'w')
            cPickle.dump(primes, mpp, protocol = -1)
            mpp.close()
            print 'Prime[%s] = %s' % (fmt_n(len(primes)), fmt_n(primes[-1]))
        except ValueError:
            interval = interval // 2
    return primes[i]

    gets prime(i)
    input: number
    return: number
    
recipes/Python/576380_Prime_look_up_program/recipe-576380.py