Станислав обнови решението на 30.04.2012 17:40 (преди над 12 години)
+def primes():
+ number = 2
+ while True:
+ #square root is included in the range
+ range_limit = int(number ** 0.5) + 1
+ if all([number % divisor for divisor in range(2, range_limit)]):
+ yield number
+ number += 1
+
+def is_prime(number):
+ for divisor in range(2, (int(number ** 0.5) + 1)):
+ if number % divisor == 0:
+ return False
+ return True
+
+def semiprimes():
+ number = 4
+ while True:
+ divisors = [divisor for divisor in range(2, number)
+ if number % divisor == 0]
+ if len(divisors) in [1, 2] and all(map(is_prime, divisors)):
+ yield number
+ number += 1
+
+