| Conditions | 5 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function countPrimes(int $n): int |
||
| 10 | { |
||
| 11 | if ($n <= 1) { |
||
| 12 | return 0; |
||
| 13 | } |
||
| 14 | [$cnt, $arr] = [0, array_fill(0, $n, false)]; |
||
| 15 | for ($i = 2; $i < $n; $i++) { |
||
| 16 | if (!$arr[$i]) { |
||
| 17 | $cnt++; |
||
| 18 | for ($j = 2; $i * $j < $n; $j++) { |
||
| 19 | $arr[$i * $j] = true; |
||
| 20 | } |
||
| 21 | } |
||
| 22 | } |
||
| 23 | |||
| 24 | return $cnt; |
||
| 25 | } |
||
| 45 |