Created
December 5, 2020 10:46
-
-
Save romanitalian/dcd3d581c7b70464d625cc1567daeb59 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
function isPrime($num) | |
{ | |
if ($num == 2) { | |
return true; | |
} | |
if ($num == 1 || $num %2 == 0) { | |
return false; | |
} | |
$to = sqrt($num) + 1; | |
for ($i = 3; $i <= $to; $i += 2) { | |
if ($num % $i == 0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
function run($N) | |
{ | |
for ($i = 0; $i <= $N; $i++) { | |
$isPrime = isPrime($i); | |
// if ($isPrime) { | |
// var_dump($i); | |
// } | |
} | |
} | |
function main() | |
{ | |
$st = microtime(true); | |
run(10000000); | |
echo microtime(true) - $st; | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment