Светослав обнови решението на 23.04.2012 03:10 (преди над 12 години)
+from math import sqrt
+
+def primes():
+ number = 2
+ while True:
+ if all([number % divisor != 0
+ for divisor in range(2, int(sqrt(number)) + 1)]):
+ yield number
+ number += 1
+
+def get_primes(upper_limit):
+ primes_list = []
+ prime = primes()
+ value = next(prime)
+ while value <= upper_limit:
+ primes_list.append(value)
+ value = next(prime)
+ return primes_list
+
+def semiprimes():
+ prime = primes()
+ value = next(prime)
+ min_current_semiprime = 0
+ current_list = []
+ while True:
+ max_current_semiprime = value * value
+ max_needed_primes_list = get_primes(max_current_semiprime // 2)
+ for number in range(min_current_semiprime, max_current_semiprime):
+ for divisor in max_needed_primes_list:
+ if number / divisor in max_needed_primes_list:
+ current_list.append(number)
+ current_list = list(set(current_list))
+ current_list.sort()
+ current_list.reverse()
+ while len(current_list) != 0:
+ yield current_list.pop()
+ min_current_semiprime = max_current_semiprime
+ value = next(prime)