Димитър обнови решението на 22.04.2012 14:29 (преди над 12 години)
+import math
+
+def is_prime(number):
+ upper_limit = int(math.sqrt(number)) + 1
+ for possible_divisor in range(2, upper_limit):
+ if (number % possible_divisor == 0):
+ return False
+ return True
+
+def primes():
+ current_number = 2;
+ while True:
+ if is_prime(current_number):
+ yield current_number
+ current_number += 1
+
+def is_semiprime(number):
+ prime = primes()
+ current_prime = next(prime);
+ primes_counter = 0
+ while number > 1:
+ while number % current_prime == 0:
+ number //= current_prime
+ primes_counter += 1
+ current_prime = next(prime)
+ return primes_counter == 2
+
+def semiprimes():
+ current_number = 4
+ while True:
+ if is_semiprime(current_number):
+ yield current_number
+ current_number += 1