Иво обнови решението на 03.05.2012 17:07 (преди над 12 години)
+def primes():
+ D = {}
+ number = 2
+ while True:
+ if number not in D:
+ yield number
+ D[number * number] = [number]
+ else:
+
+ for prime in D[number]:
+ D.setdefault(prime + number, []).append(prime)
+ del D[number]
+ number += 1
+
+def get_prime(prime_index):
+ primes = []
+ prime_generator = primes()
+ if prime_index == 0:
+ return 2
+ if ( prime_index > len(primes) ):
+ for i in range(len(primes), prime_index):
+ primes.append(next(prime_generator))
+ return primes[prime_index -1]
+
+
+def semiprimes():
+ pass # :D
+
+def counting_sort(array, maxval):
+ n = len(array)
+ m = maxval + 1
+ count = [0] * m
+ for a in array:
+ count[a] += 1
+ i = 0
+ for a in range(e):
+ for c in range(count[a]):
+ array[i] = a
+ i += 1
+ return array