Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One possible realization as a generator :

def PGm1(k):
    Returns a generator for the sequence p(i)^k-1  in i
    where p(i) is the i-th prime.

    Example : the n first terms of the sequence can be obtained by :

        Gk = PGm1(k)
        list(Gk.__next__() for u in range(n))
    r = 0
    while True:
        r = r.next_prime()
        yield r^k - 1

Example of use :

sage: G2=PGm1(2)
sage: list(G2.__next__() for u in range(5))
[3, 8, 24, 48, 120]

Beware : this generator is infinite. Using it "raw" won't return...