function count_primes($from, $to) { Primes::computeTo($to); return Primes::count($from, $to); }
{ if (in_array($value, self::$known_primes)) { return true; } for ($i = 0; $i < count(self::$known_primes); $i++) { $prime = self::$known_primes[$i]; if ($value % $prime == 0) { return false; } } self::$known_primes[] = $value; return true; } } class Primes { public static function upTo($max) { $result = array(2); $prime = new Prime(3); while ($prime->lessThan($max)) { $result[] = $prime->value; $prime = $prime->next(); } return $result; } } foreach (file($argv[1]) as $line) { $max = trim($line); echo implode(",", Primes::upTo($max)) . "\n"; }