Лидия обнови решението на 01.05.2012 19:37 (преди над 12 години)
+def primes():
+ prime, is_prime = 2, True
+ while True:
+ for number in range(2, prime):
+ if prime % number == 0:
+ is_prime = False
+ break
+ if is_prime == True:
+ yield prime
+ prime += 1
+ is_prime = True
+
+
+def semiprimes():
+ number = 4
+ while True:
+ if count_prime_factors(number) == 2:
+ yield number
+ number += 1
+
+
+def count_prime_factors(number):
+ divisor, prime_factors = 2, []
+ while divisor <= number:
+ if number % divisor == 0:
+ prime_factors.append(divisor)
+ number = number / divisor
+ else:
+ divisor += 1
+ return len(prime_factors)