Дамяна обнови решението на 03.05.2012 09:21 (преди над 12 години)
+from math import sqrt
+
+def is_prime(number):
+ if all([number % div for div in range(2, int(sqrt(number)) + 1)]):
+ return True
+ return False
+
+def primes():
+ prime = 2
+ while True:
+ if is_prime(prime):
+ yield prime
+ prime += 1
+
+def semiprimes():
+ semiprime = 4
+ while True:
+ sprime = semiprime
+ divisors = []
+ p = primes()
+ div = next(p)
+ while sprime != 1:
+ while sprime % div == 0:
+ divisors.append(div)
+ sprime /= div
+ div = next(p)
+ if(len(divisors) == 2):
+ yield semiprime
+ semiprime += 1