To optimize the approach, we will rule out the numbers above 1000, whose first or last three digits are not prime >>> validate(74679) False >>> validate(235693) False >>> validate(3797) True
(n: int)
| 75 | |
| 76 | |
| 77 | def validate(n: int) -> bool: |
| 78 | """ |
| 79 | To optimize the approach, we will rule out the numbers above 1000, |
| 80 | whose first or last three digits are not prime |
| 81 | >>> validate(74679) |
| 82 | False |
| 83 | >>> validate(235693) |
| 84 | False |
| 85 | >>> validate(3797) |
| 86 | True |
| 87 | """ |
| 88 | return not ( |
| 89 | len(str(n)) > 3 |
| 90 | and (not is_prime(int(str(n)[-3:])) or not is_prime(int(str(n)[:3]))) |
| 91 | ) |
| 92 | |
| 93 | |
| 94 | def compute_truncated_primes(count: int = 11) -> list[int]: |
no test coverage detected