Last active
November 1, 2018 18:29
-
-
Save gutoccs/de66d3607556eb423df4335b98eee726 to your computer and use it in GitHub Desktop.
Cálculo de los números primos que hay hasta un entero 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Cálculo de los números primos que hay hasta un número n</title> | |
</head> | |
<body> | |
<?php | |
$inicio = microtime(true); | |
$numero = 0; | |
$divisor = 0; | |
$n = 100000; | |
$esPrimo = 0; | |
for ($numero=2; $numero<=$n; $numero++) { | |
$esPrimo=1; | |
for ($divisor=2; $divisor<=sqrt($numero); $divisor++) { | |
if ($numero%$divisor==0) { | |
$esPrimo=0; | |
break; | |
} | |
} | |
//if($esPrimo==1) echo $numero."<br>"; | |
} | |
$tiempo = microtime(true) - $inicio; | |
echo 'fin'; | |
echo "<br>".'Tiempo Total: ' . $tiempo . ' segundos.'; | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Código usado en mi Blog gutoccs.wordpress.com para el artículo Comparando el rendimiento de 3 versiones de PHP.