import time
def sieve_of_eratosthenes(limit):
primes = [True] * (limit + 1)
primes[0] = primes[1] = False # 0 y 1 no son primos
for i in range(2, int(limit**0.5) + 1):
if primes[i]:
for j in range(i * i, limit + 1, i):
primes[j] = False
return [i for i, is_prime in enumerate(primes) if is_prime]
# Límite
limit = 100000 # Cambia este valor si lo deseas
# Temporizador
start_time = time.time()
primes = sieve_of_eratosthenes(limit)
end_time = time.time()
# Resultados
print(f"Primos hasta {limit}: {len(primes)} encontrados.")
print(f"Tiempo de ejecución: {end_time - start_time:.6f} segundos.")
aW1wb3J0IHRpbWUKCmRlZiBzaWV2ZV9vZl9lcmF0b3N0aGVuZXMobGltaXQpOgogICAgcHJpbWVzID0gW1RydWVdICogKGxpbWl0ICsgMSkKICAgIHByaW1lc1swXSA9IHByaW1lc1sxXSA9IEZhbHNlICAjIDAgeSAxIG5vIHNvbiBwcmltb3MKICAgIGZvciBpIGluIHJhbmdlKDIsIGludChsaW1pdCoqMC41KSArIDEpOgogICAgICAgIGlmIHByaW1lc1tpXToKICAgICAgICAgICAgZm9yIGogaW4gcmFuZ2UoaSAqIGksIGxpbWl0ICsgMSwgaSk6CiAgICAgICAgICAgICAgICBwcmltZXNbal0gPSBGYWxzZQogICAgcmV0dXJuIFtpIGZvciBpLCBpc19wcmltZSBpbiBlbnVtZXJhdGUocHJpbWVzKSBpZiBpc19wcmltZV0KCiMgTMOtbWl0ZQpsaW1pdCA9IDEwMDAwMCAgIyBDYW1iaWEgZXN0ZSB2YWxvciBzaSBsbyBkZXNlYXMKCiMgVGVtcG9yaXphZG9yCnN0YXJ0X3RpbWUgPSB0aW1lLnRpbWUoKQpwcmltZXMgPSBzaWV2ZV9vZl9lcmF0b3N0aGVuZXMobGltaXQpCmVuZF90aW1lID0gdGltZS50aW1lKCkKCiMgUmVzdWx0YWRvcwpwcmludChmIlByaW1vcyBoYXN0YSB7bGltaXR9OiB7bGVuKHByaW1lcyl9IGVuY29udHJhZG9zLiIpCnByaW50KGYiVGllbXBvIGRlIGVqZWN1Y2nDs246IHtlbmRfdGltZSAtIHN0YXJ0X3RpbWU6LjZmfSBzZWd1bmRvcy4iKQo=