print("Number of primes must be greater than 2")
number = int(input("Number of primes: "))
if number < 1:
print("Invalid input")
exit()
print(2)
print(3)
i = 0
no_primes = 2
while 1 < 2:
m = 6 * i - 1
n = 6 * i + 1
if (2 ** m) % m == 2:
print(m)
no_primes += 1
if no_primes == number:
break
if (2 ** n) % n == 2:
print(n)
no_primes += 1
if no_primes == number:
break
i += 1
My code uses the fact that primes can be expressed in the form 6n-1 or 6n+1 except for 2 and 3. My while loop looks quite strange but I don't have the expertise to manoeuvre with loops consisting of two variables (no_primes and i in this case). When I generate the first 1000 primes, it skips a few, ending with 7789 instead of 7919. Does anybody know why? Also, sorry if the code looks redundant. If it is, please do state how I can improve it
I started python only a few weeks ago, thought you'll should know