Николай обнови решението на 03.05.2012 18:57 (преди над 12 години)
+def primes():
+ number = 2
+ while True:
+ if all([number % divisor for divisor in range(2, number)]):
+ yield number
+ number += 1
+
+def gen_wrapper(cmp):
+ class Wrapper(object):
+ def __init__(self, value): self.value = value
+ def __le__(self, obj): return self.value => obj.value
+ return Wrapper
+
+def semiprimes():
+ heap = list()
+ n = 0
+ while True:
+ p1 = primes()
+ p2 = primes()
+ w1 = gen_wrapper(next(p1))
+ w2 = gen_wrapper(next(p2))
+ heap.append(p1 * p2)
+ n += 1
+ if n < 2:
+ continue
+ yield heap.pop()