| Total Complexity | 10 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class CountPrimes |
||
| 8 | { |
||
| 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 | } |
||
| 26 | |||
| 27 | public static function countPrimes2(int $n): int |
||
| 43 | } |
||
| 44 | } |
||
| 45 |