Явор обнови решението на 03.05.2012 18:55 (преди над 12 години)
+def primes():
+ current_prime = 2
+ while True:
+ if all((current_prime % x != 0
+ for x in range(2, upper_bound(current_prime)))):
+ yield current_prime
+ current_prime += 1
+
+
+upper_bound = lambda x: int(x ** 0.5 + 0.5) + 1
+
+
+def semiprimes():
+ current_semiprime = 2
+ while True:
+ if sum((current_semiprime % x == 0 and
+ (1 + (current_semiprime % x ** 2 == 0
+ and current_semiprime != x ** 2))
+ for x in range(2, upper_bound(current_semiprime)))) == 1:
+ yield current_semiprime
+ current_semiprime += 1