Албена обнови решението на 03.05.2012 09:56 (преди над 12 години)
+primeNumbers = []
+semiPrimes = []
+var = currentStart = None
+
+
+def primes():
+ if not primeNumbers:
+ primeNumbers.append(2)
+ yield 2
+ if len(primeNumbers) == 1:
+ primeNumbers.append(3)
+ yield 3
+
+ for m in myrange(3, 2):
+ if all([m % p for p in primeNumbers]):
+ primeNumbers.append(m)
+ yield m
+
+
+def semiprimes():
+ if not semiPrimes:
+ semiPrimes.append(4)
+ yield 4
+
+ for m in myrange(5, 1):
+ if m in semiPrimes:
+ continue
+ if not primeNumbers:
+ next(primes())
+ while primeNumbers[len(primeNumbers) - 1] < m / 2:
+ next(primes())
+ for prime in primeNumbers:
+ if m in map(lambda x: x * prime, primeNumbers):
+ semiPrimes.append(m)
+ yield m
+ break
+
+
+def myrange(start, step):
+ global currentStart, var
+ if start != currentStart:
+ var = start
+ currentStart = start
+
+ while(True):
+ var += step
+ yield var - step