Георги обнови решението на 02.05.2012 01:27 (преди над 12 години)
+import heapq
+
+def prime(number):
+ for divisor in range(2, number):
+ if number % divisor == 0:
+ return False
+
+ return True
+
+def primes():
+ current_number = 2
+ while True:
+ if prime(current_number):
+ yield current_number
+ current_number += 1
+
+
+def semiprimes():
+ primes_stream = primes()
+ heap = []
+ push = lambda x: heapq.heappush(heap,x)
+ pop = lambda : heapq.heappop(heap)
+ primes_list = []
+ while True:
+ current_prime = next(primes_stream)
+ primes_list.append(current_prime)
+ for semiprime in map(lambda x: current_prime * x, primes_list):
+ push(semiprime)
+
+ yield pop()