Стела обнови решението на 26.04.2012 15:09 (преди над 12 години)
+from math import sqrt, floor
+
+
+def primes():
+ number = 2
+ while True:
+ if all([number % div for div in range(2, floor(sqrt(number)) + 1)]):
+ yield number
+ number += 1
+
+
+def semiprimes():
+ number = 4
+ primes_generator = primes()
+ prime_numbers = [next(primes_generator), ]
+ multiplied_primes = {prime_numbers[-1] ** 2, }
+ while True:
+ if number in multiplied_primes:
+ yield number
+ number += 1
+ if number / 2 > sorted(prime_numbers)[-1]:
+ prime_numbers.append(next(primes_generator))
+ multiplied_primes.update({x * y for x in prime_numbers
+ for y in prime_numbers})