mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-04-19 04:07:36 +00:00
Improve Project Euler problem 203 solution 1 (#4807)
This commit is contained in:
parent
a4d68d69f1
commit
629369a34f
@ -75,17 +75,15 @@ def get_primes_squared(max_number: int) -> list[int]:
|
|||||||
>>> get_primes_squared(100)
|
>>> get_primes_squared(100)
|
||||||
[4, 9, 25, 49]
|
[4, 9, 25, 49]
|
||||||
"""
|
"""
|
||||||
max_prime = round(math.sqrt(max_number))
|
max_prime = math.isqrt(max_number)
|
||||||
non_primes = set()
|
non_primes = [False] * (max_prime + 1)
|
||||||
primes = []
|
primes = []
|
||||||
for num in range(2, max_prime + 1):
|
for num in range(2, max_prime + 1):
|
||||||
if num in non_primes:
|
if non_primes[num]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
counter = 2
|
for num_counter in range(num ** 2, max_prime + 1, num):
|
||||||
while num * counter <= max_prime:
|
non_primes[num_counter] = True
|
||||||
non_primes.add(num * counter)
|
|
||||||
counter += 1
|
|
||||||
|
|
||||||
primes.append(num ** 2)
|
primes.append(num ** 2)
|
||||||
return primes
|
return primes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user