Виктор обнови решението на 28.04.2012 15:10 (преди над 12 години)
+import math
+
+def primes():
+ number = 2
+ yield number
+ number = 3
+ while True:
+ if all([number % divisor for divisor in
+ range(3, math.floor(math.sqrt(number)) + 1, 2)]):
+ yield number
+ number += 2
+
+
+def is_prime(number):
+ if number == 2:
+ return True
+ if not (number % 2):
+ return False
+ if all([number % divisor for divisor in
+ range(3, math.floor(math.sqrt(number)) + 1, 2)]):
+ return True
+ return False
+
+def semiprimes():
+ semiprime = 4
+
+ while True:
+ prime_divisor_gen = primes()
+ prime_divisor = next(prime_divisor_gen)
+
+ while(prime_divisor <= math.floor(math.sqrt(semiprime))):
+
+ if ((not (semiprime % prime_divisor)) and
+ is_prime(semiprime/prime_divisor)) :
+ yield semiprime
+ prime_divisor = next(prime_divisor_gen)
+ semiprime += 1