Станислав обнови решението на 22.04.2012 21:45 (преди над 12 години)
+def isprime(num):
+ remainders = (num % n for n in range(2, int(num ** 0.5 + 1)))
+ return num > 1 and all(remainders)
+
+
+def primes():
+ num = 2
+ while True:
+ if isprime(num):
+ yield num
+ num += 1
+
+
+def semiprimes():
+ num = 2
+ while True:
+ for n in range(2, int(num ** 0.5 + 1) + 1):
+ if not num % n and isprime(n) and isprime(num // n):
+ yield num
+ break
+ num += 1