Created
January 20, 2016 15:57
-
-
Save reginaldojunior/56cacd3f52d9b707579d to your computer and use it in GitHub Desktop.
Solução para a primeira etapa do desafio para Vaga de Programador PHP Junior na SexLog (https://www.sexlog.com/desafiosexlogphp)
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
#!/usr/bin/php | |
<?php | |
function isPrimo($n){ | |
if($n<5 || $n%2==0 || $n%3==0) | |
return ($n==2 || $n==3); | |
$maxP = sqrt($n)+2; | |
for($p=5; $p < $maxP; $p += 6) | |
if($n % $p == 0 || $n % ($p + 2) ==0 ) | |
return false; | |
return true; | |
} | |
$find = false; | |
$data = []; | |
$i = 0; | |
$aux = 0; | |
while ($find != true) { | |
if (isPrimo($i)) { | |
$aux++; | |
if ($aux == 10001) { | |
$data = ['number' => $i]; | |
$find = true; | |
} | |
} | |
$i++; | |
var_dump($aux); | |
} | |
var_dump($data); | |
exit; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment