Димитър обнови решението на 27.04.2012 20:16 (преди над 12 години)
+import sys
+
+def primes():
+ max = sys.maxsize
+ yield 2
+ primes = []
+ for m in range(3,max,2):
+ if all(m%p for p in primes):
+ primes.append(m)
+ yield m
+
+
+
+def is_prime(n):
+ if n < 2:
+ return False
+ for x in range(2, int(n**0.5)+1):
+ if n % x == 0:
+ return False
+ return True
+
+
+def check_semiprime(number):
+ mid = int(number/2) + 1
+ divs = []
+ for i in range (2, mid):
+ if number % i == 0:
+ divs.append(i)
+ if number / i == i:
+ divs.append(i)
+ return len(divs) == 2 and is_prime(divs[0]) and is_prime(divs[1])
+
+def semiprimes():
+ sp_number = 4
+ while True:
+ yield sp_number
+ sp_number = sp_next(sp_number)
+
+def sp_next(number):
+ number += 1
+ while not check_semiprime(number):
+ number += 1
+ return number
+
+