project-euler/187_semiprimes.py

21 lines
418 B
Python
Raw Normal View History

2023-03-25 17:24:17 +01:00
#!/usr/bin/env python3
def primes(n):
count = 0
sieve = [False]*n
for p in range(2, n):
if sieve[p]:
continue
for i in range(p**2, n, p):
sieve[i] = True
np = 2*p
for p2 in range(2,p+1):
if np >= n:
break
if not sieve[p2]:
count += 1
np += p
return count
print(primes(10**8))