# list of all prime powers -1

The primes () method gives the list of all primes. Similarly, I need a list (Say PP) that consists of all $p^k-1$ where $p$ is a prime and $k \ge 1$. How to create this infinite list?

Also, I want all possible finite products of elements of PP. Using this I want to understand when two such products are equal.

How to do this? Kindly share your thoughts. Thank you.

edit retag close merge delete

Sort by » oldest newest most voted Primes() is not a list, but essentially a generator of primes with some additional functions. While it can generate primes one by one, it does not store them all at once anywhere (and so it's not a list). We can create a generator for integers of the form $p^k - 1$ in their natural order like

PP = (q-1 for q in NN if is_prime_power(q))

As for finite products of elements of PP, again we cannot store them in the list unless they are somehow bounded. So, you need to be a bit more specific how you want to generate those products.

more

PP = (q-1 for q in NN if is_prime_power(q))

This generator will return the list pf prime any power - 1, without regard to k...

I didn't read it as such ; but you may be right. In which case your brute-force solution is better than what I proposed.

For example:

for q in PP:
if q>=100:
break
print(q)


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...

more