Returns number of primes below max_prime with the property >>> solution(100) 4
(max_prime: int = 10**6)
| 30 | |
| 31 | |
| 32 | def solution(max_prime: int = 10**6) -> int: |
| 33 | """ |
| 34 | Returns number of primes below max_prime with the property |
| 35 | |
| 36 | >>> solution(100) |
| 37 | 4 |
| 38 | """ |
| 39 | |
| 40 | primes_count = 0 |
| 41 | cube_index = 1 |
| 42 | prime_candidate = 7 |
| 43 | while prime_candidate < max_prime: |
| 44 | primes_count += is_prime(prime_candidate) |
| 45 | |
| 46 | cube_index += 1 |
| 47 | prime_candidate += 6 * cube_index |
| 48 | |
| 49 | return primes_count |
| 50 | |
| 51 | |
| 52 | if __name__ == "__main__": |