You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

25 lines
372 B

#!/usr/bin/env php
<?php
# PHP version of a Prime Number Finder
# haplo@mindstab.net
$MAX = $argv[1];
if($MAX < 1)
{
print "primes.php <MAX NUM>\n";
exit;
}
for($num=3; $num<= $MAX; $num+=2)
{
$max = sqrt($num);
$isPrime = true;
for($test=3;$test <= $max; $test+=2)
{
if(! ($num % $test)) {
$isPrime= false;
break;
}
}
if($isPrime) print "$num\n";
}
?>