Created
December 15, 2019 20:35
-
-
Save Fhernd/6b672cb1774c3dc607362b9ac6e564bf to your computer and use it in GitHub Desktop.
# Ejercicio 330: Usar el método de Criba de Eratóstenes para generar números primos hasta n.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ejercicio 330: Usar el método de Criba de Eratóstenes para generar números primos hasta n. | |
def criba_eratostenes(n): | |
primos = [] | |
no_primos = [] | |
for i in range(2, n + 1): | |
if i not in no_primos: | |
primos.append(i) | |
for j in range(i * i, n + 1, i): | |
no_primos.append(j) | |
return primos | |
print(criba_eratostenes(120)) | |
print(len(criba_eratostenes(120))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excelente la lógica aplica. Solo me animaría a comentar que en la entrada 11 también funciona esta versión: for j in range(i , n + 1, i):