27 lines
No EOL
929 B
Text
27 lines
No EOL
929 B
Text
def sieve_of_eratosthenes(n):
|
|
"""
|
|
Generate a list of prime numbers up to n using the Sieve of Eratosthenes algorithm.
|
|
"""
|
|
is_prime = [True] * (n + 1)
|
|
p = 2
|
|
while (p * p <= n):
|
|
if (is_prime[p] == True):
|
|
for i in range(p * p, n + 1, p):
|
|
is_prime[i] = False
|
|
p += 1
|
|
prime_numbers = [p for p in range(2, n) if is_prime[p]]
|
|
return prime_numbers
|
|
|
|
# We need to find the upper limit for the sieve to ensure we get at least 1000 primes.
|
|
# A rough estimate for the nth prime is n * log(n * log(n)), but we'll use a safe upper bound.
|
|
|
|
def find_first_1000_primes():
|
|
upper_limit = 10000 # A safe upper limit to ensure we get at least 1000 primes
|
|
primes = sieve_of_eratosthenes(upper_limit)
|
|
return primes[:1000]
|
|
|
|
# Get the first 1000 prime numbers
|
|
first_1000_primes = find_first_1000_primes()
|
|
|
|
# Print the first 1000 prime numbers
|
|
print(first_1000_primes) |