Николай обнови решението на 22.04.2012 19:30 (преди над 12 години)
+def primes():
+ primes = []
+ current_number = 2;
+ while True:
+ if all(current_number % prime != 0 for prime in primes):
+ primes.append(current_number)
+ yield current_number
+ current_number += 1
+
+def semiprimes():
+ primes = []
+ current_number = 2;
+ while True:
+ divisor_count = 0
+ for prime in primes:
+ number = current_number
+ while number % prime == 0:
+ number /= prime
+ divisor_count += 1
+ if divisor_count == 0:
+ primes.append(current_number)
+ elif divisor_count == 2:
+ yield current_number
+ current_number += 1