Недислав обнови решението на 02.05.2012 20:13 (преди над 12 години)
+def primes():
+ number = 2
+ while True:
+ if all([number % divisor for divisor in range(2, number)]):
+ yield number
+ number += 1
+
+def get_primes(number):
+ p = primes()
+ prime_numbers = []
+ for x in range(number):
+ prime_numbers.append(next(p))
+ return prime_numbers
+
+def semiprimes():
+ prime_numbers = 10
+ semiprimes = []
+ nat_counter = 100
+ while True:
+ primes = get_primes(prime_numbers)
+ for x in range(0, len(primes)):
+ for y in range(0, len(primes)):
+ nat_numbers = range(3, nat_counter)
+ if primes[x] * primes[y] in nat_numbers:
+ semiprimes.append(primes[x] * primes[y])
+ nat_counter += 100
+ for semiprime in sorted(set(semiprimes)):
+ yield semiprime
+ prime_numbers += 1