Дарина обнови решението на 30.04.2012 22:11 (преди над 12 години)
+import math
+
+
+def primes():
+ number = 2
+ while True:
+ limit = int(math.sqrt(number)) + 1
+ if all([number % divisor != 0 for divisor in range(2, limit)]):
+ yield number
+ number += 1
+
+
+def is_prime(number):
+ limit = int(math.sqrt(number)) + 1
+ for x in range(2, limit):
+ if number % x == 0:
+ return False
+ return True
+
+
+def semiprimes():
+ number = 2
+ while True:
+ r = range(2, number)
+ for x in r:
+ for y in r:
+ if number / x == y and is_prime(x) and is_prime(y):
+ yield number
+ number += 1
+ number += 1