Skip to content

Instantly share code, notes, and snippets.

@reginaldojunior
Created January 20, 2016 15:57
Show Gist options
  • Save reginaldojunior/56cacd3f52d9b707579d to your computer and use it in GitHub Desktop.
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)
#!/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