Щилиян обнови решението на 03.05.2012 18:55 (преди над 12 години)
+import math
+
+def is_prime(number):
+ start = 3
+ end = math.sqrt(number)
+ while start <= end:
+ if number % start == 0: return False
+ start = start + 2
+ return True
+
+
+def primes():
+ primes_candidate = list(range(3, 1000000, 2))
+ primes_candidate.insert(0, 2)
+ for num in primes_candidate:
+ if is_prime(num): yield num
+
+def semi_primes():
+ pi = primes()
+ p = []
+ p.append(next(pi))
+ i = 0
+ while True:
+ j = i
+ while j >= 0:
+ yield p[i] * p[j]
+ j = j - 1
+ p.append(next(pi))
+ i = len(p) - 1
+