Илия обнови решението на 02.05.2012 23:56 (преди над 12 години)
+def primes():
+ number = 2
+ while True:
+ if all([number % i for i in range(2, (number // 2) + 1)]):
+ yield number
+ number += 1
+
+
+def semiprimes():
+ primes_list = []
+ iterator = primes()
+ number = 4
+ prim = next(iterator)
+ oldprim = prim
+ while True:
+ while number > prim:
+ primes_list.append(prim)
+ prim = next(iterator)
+ if oldprim != prim:
+ semiprimes_set = {i * j for i in primes_list for j in primes_list}
+ oldprim = prim
+ if number in semiprimes_set:
+ yield number
+ number = number + 1