Борис обнови решението на 24.04.2012 16:36 (преди над 12 години)
+def primes():
+ number = 2
+ while True:
+ if all([number % divisor for divisor in range(2, number)]):
+ yield number
+ number += 1
+
+
+def semiprimes():
+ semiprime_number = 1
+ while True:
+ factor = get_factor(semiprime_number)
+ if factor and get_factor(semiprime_number // factor) == None:
+ yield semiprime_number
+ semiprime_number += 1
+
+
+def get_factor(semiprime_number):
+ for index in range(2, semiprime_number-1):
+ if semiprime_number % index == 0:
+ return index