-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem204.py
More file actions
30 lines (26 loc) · 743 Bytes
/
problem204.py
File metadata and controls
30 lines (26 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from itertools import compress
import time
def findPrimes(n):
sieve = bytearray([True]) * (n//2+1)
for i in range(1,int(n**0.5)//2+1):
if sieve[i]:
sieve[2*i*(i+1)::2*i+1] = bytearray((n//2-2*i*(i+1))//(2*i+1)+1)
return [2,*compress(range(3,n,2), sieve[1:])]
def compute():
LIMIT = 10**9
primes = findPrimes(100)
def count(primeindex, product):
if primeindex == len(primes):
return 1 if product <= LIMIT else 0
else:
result = 0
while product <= LIMIT:
result += count(primeindex + 1, product)
product *= primes[primeindex]
return result
return str(count(0, 1))
start = time.time()
result = compute()
print(result)
end = time.time()
print("Running time is %ss" % (end - start))