Prime decomposition: Difference between revisions

Content added Content deleted
(→‎E: Add EasyLang)
(→‎Python: Using Croft Spiral sieve: ~9% faster by using index-based lookups)
Line 4,084: Line 4,084:
yield p
yield p
roots = {9: 3, 25: 5} # Map d**2 -> d.
roots = {9: 3, 25: 5} # Map d**2 -> d.
primeroots = frozenset((1, 7, 11, 13, 17, 19, 23, 29))
not_primeroot = tuple(x not in {1,7,11,13,17,19,23,29} for x in range(30))
selectors = (1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0)
selectors = (1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0)
for q in compress(
for q in compress(
Line 4,098: Line 4,098:
del roots[q]
del roots[q]
x = q + 2*p
x = q + 2*p
while x in roots or (x % 30) not in primeroots:
while not_primeroot[x % 30] or x in roots:
x += 2*p
x += 2*p
roots[x] = p
roots[x] = p