Дин обнови решението на 01.05.2012 18:59 (преди над 12 години)
+def primes():
+ number = 2
+ while True:
+ if all([number % divisor for divisor in range(2, number)]):
+ yield number
+ number += 1
+
+
+def semiprimes():
+ number = 4
+ while True:
+ gen1 = primes()
+ sq_root = number ** (0.5)
+ f1 = next(gen1)
+ while f1 <= sq_root:
+ gen2 = primes()
+ f2 = next(gen2)
+ while f2 <= number:
+ if number == f1 * f2:
+ yield number
+ f2 = next(gen2)
+ f1 = next(gen1)
+ number += 1