Виктор обнови решението на 25.04.2012 17:50 (преди над 12 години)
+def primes():
+ yield 2
+ current = 3
+ while True:
+ if is_prime(current):
+ yield current
+ current += 2
+
+def is_prime(checked, cached_primes=[2,]):
+ for prime in cached_primes:
+ if prime**2 > checked:
+ break
+ if checked % prime == 0:
+ return False
+ cached_primes.append(checked)
+ return True
+
+def semiprimes():
+ current = 4
+ while True:
+ if is_semiprime(current):
+ yield current
+ current += 1
+
+def is_semiprime(checked):
+ for prime in primes():
+ if prime**2 > checked:
+ return False
+ if checked % prime == 0:
+ return is_prime(checked/prime)
+
+def count():
+ start = time.time()
+ for prime in primes():
+ if prime > 10000000:
+ break
+ end = time.time()
+ print((end-start)/60)