Diferencia entre revisiones de «Implementación de algoritmos de teoría de números/Criba de Eratóstenes»
Contenido eliminado Contenido añadido
Cambio de tag |
+orden |
||
Línea 396:
criba_eratostenes(1000)
</syntaxhighlight>▼
=== R ===▼
<syntaxhighlight lang="r">▼
primos<-function(n){▼
posibles<-seq(1,n,by=2)▼
posibles[1]<-2▼
for(i in 2:round(sqrt(n))){▼
if(posibles[i]!=0){▼
for(j in seq(i + posibles[i], n/2, by=posibles[i])){▼
posibles[j]<-0▼
}▼
}▼
}▼
return(posibles[posibles!=0])▼
}▼
primos(10000)▼
</syntaxhighlight>
Línea 440 ⟶ 457:
End Sub
End Module
▲</syntaxhighlight>
▲=== R ===
▲<syntaxhighlight lang="r">
▲primos<-function(n){
▲ posibles<-seq(1,n,by=2)
▲ posibles[1]<-2
▲ for(i in 2:round(sqrt(n))){
▲ if(posibles[i]!=0){
▲ for(j in seq(i + posibles[i], n/2, by=posibles[i])){
▲ posibles[j]<-0
▲ }
▲ }
▲ }
▲ return(posibles[posibles!=0])
▲}
▲primos(10000)
</syntaxhighlight>
|