Николина обнови решението на 02.05.2012 18:09 (преди над 12 години)
+def primes():
+ yield 2
+ number = 3
+ while True:
+ if all([number % divisor
+ for divisor in range(3, int(number ** 0.5) + 1, 2)]):
+ yield number
+ number += 2
+
+
+def is_prime(number):
+ if number == 1:
+ return False
+ if number == 2:
+ return True
+ if number % 2 == 0:
+ return False
+ if all([number % divisor
+ for divisor in range(3, int(number ** 0.5) + 1, 2)]):
+ return True
+ return False
+
+
+def semiprimes():
+ number = 2
+
+ while True:
+ smallest_divisor = number
+ for divisor in range(2, int(number ** 0.5) + 1):
+ if number % divisor == 0:
+ smallest_divisor = divisor
+ break
+ if is_prime(number / smallest_divisor):
+ yield number
+ number += 1