Методи обнови решението на 03.05.2012 15:05 (преди над 12 години)
+from math import sqrt
+
+def primes(iterations_limiter = 0):
+"""
+ Generator for prime numbers.
+"""
+ following_number = 2
+ while 1:
+ number_below_following = round(sqrt(following_number), 0)
+ is_prime = True
+ while number_below_following > 1:
+ if not following_number % number_below_following:
+ is_prime = False
+ break
+ number_below_following -= 1
+ if is_prime: yield(following_number)
+ following_number += 1
+ if iterations_limiter and iterations_limiter < following_number:
+ break
+
+def semiprimes():
+"""
+ Generates multiplied prime numbers.
+"""
+ following_number = 2
+ while 1:
+ possibilities = []
+ for a in primes(following_number):
+ for b in primes(following_number):
+ if a * b > following_number: possibilities.append(a * b)
+ following_number = min(possibilities)
+ yield following_number