Лъчезар обнови решението на 03.05.2012 17:45 (преди над 12 години)
+from math import *
+def isPrime(i):
+ for x in range(2,round(sqrt(i))+1):
+ if i % x == 0:
+ return False
+ return True
+
+def primes():
+ def make_generator():
+ i = 2
+ while(True):
+ if isPrime(i):
+ yield i
+ i+=1
+ return iter(make_generator())
+
+def semiprimes():
+ def make_generator():
+ i = 4
+ primes_set = set([])
+ primes_generator = primes()
+ current_prime = next(primes_generator)
+ while(True):
+ if current_prime <= i // 2:
+ primes_set.add(current_prime)
+ current_prime = next(primes_generator)
+ for x in primes_set:
+ if (i / x) in primes_set:
+ yield i
+ break
+ i+=1
+ return iter(make_generator())