wheel-factorization

2-3-5-7 wheel factorization seems to skip prime number 331

家住魔仙堡 提交于 2020-01-01 15:07:13
问题 When following the procedure on wikipedia for wheel factorization, I seem to have stumbled into a problem where the prime number 331 is treated as a composite number if I try to build a 2-3-5-7 wheel. With 2-3-5-7 wheel, 2*3*5*7=210. So I setup a circle with 210 slots and go through steps 1-7 without any issues. Then I get to step 8 and strike off the spokes of all multiples of prime numbers, I eventually strike off the spoke rooted at 121, which is a multiple of 11, which is a prime. For the

Why does function apply complain about long lists?

给你一囗甜甜゛ 提交于 2019-12-22 08:24:54
问题 As part of some Eulerian travails, I'm trying to code a Sieve of Eratosthenes with a factorization wheel. My code so far is: (defun ring (&rest content) "Returns a circular list containing the elements in content. The returned list starts with the first element of content." (setf (cdr (last content)) content)) (defun factorization-wheel (lst) "Returns a circular list containing a factorization wheel using the list of prime numbers in lst" (let ((circumference (apply #'* lst))) (loop for i

Sieve of Eratosthenes with Wheel Factorization

早过忘川 提交于 2019-12-21 20:53:09
问题 i'm implementing a reasonably fast prime number generator and i obtained some nice results with a few optimizations on the sieve of eratosthenes. In particular, during the preliminary part of the algorithm, i skip all multiples of 2 and 3 in this way: template<class Sieve, class SizeT> void PrimeGenerator<Sieve, SizeT>::factorize() { SizeT c = 2; m_sieve[2] = 1; m_sieve[3] = 1; for (SizeT i=5; i<m_size; i += c, c = 6 - c) m_sieve[i] = 1; } Here m_sieve is a boolean array according to the

Why does function apply complain about long lists?

柔情痞子 提交于 2019-12-05 13:24:53
As part of some Eulerian travails , I'm trying to code a Sieve of Eratosthenes with a factorization wheel. My code so far is: (defun ring (&rest content) "Returns a circular list containing the elements in content. The returned list starts with the first element of content." (setf (cdr (last content)) content)) (defun factorization-wheel (lst) "Returns a circular list containing a factorization wheel using the list of prime numbers in lst" (let ((circumference (apply #'* lst))) (loop for i from 1 to circumference unless (some #'(lambda (x) (zerop (mod i x))) lst) collect i into wheel finally

2-3-5-7 wheel factorization seems to skip prime number 331

这一生的挚爱 提交于 2019-12-04 12:37:00
When following the procedure on wikipedia for wheel factorization , I seem to have stumbled into a problem where the prime number 331 is treated as a composite number if I try to build a 2-3-5-7 wheel. With 2-3-5-7 wheel, 2*3*5*7=210. So I setup a circle with 210 slots and go through steps 1-7 without any issues. Then I get to step 8 and strike off the spokes of all multiples of prime numbers, I eventually strike off the spoke rooted at 121, which is a multiple of 11, which is a prime. For the spoke rooted at 121, 121 + 210 = 331. Unfortunately, 331 is a prime number. Is the procedure on

Sieve of Eratosthenes with Wheel Factorization

江枫思渺然 提交于 2019-12-04 12:27:45
i'm implementing a reasonably fast prime number generator and i obtained some nice results with a few optimizations on the sieve of eratosthenes. In particular, during the preliminary part of the algorithm, i skip all multiples of 2 and 3 in this way: template<class Sieve, class SizeT> void PrimeGenerator<Sieve, SizeT>::factorize() { SizeT c = 2; m_sieve[2] = 1; m_sieve[3] = 1; for (SizeT i=5; i<m_size; i += c, c = 6 - c) m_sieve[i] = 1; } Here m_sieve is a boolean array according to the sieve of eratosthenes. I think this is a sort of Wheel factorization only considering primes 2 and 3,

Adding wheel factorization to an indefinite sieve

只谈情不闲聊 提交于 2019-11-27 02:21:38
I’m modifying an indefinite sieve of Eratosthenes from here so it uses wheel factorization to skip more composites than its current form of just checking all odds. I’ve worked out how to generate the steps to take to reach all the gaps along the wheel. From there I figured I could just substitute the +2’s for these wheel steps but it’s causing the sieve to skip primes. Here's the code: from itertools import count, cycle def dvprm(end): "finds primes by trial division. returns a list" primes=[2] for i in range(3, end+1, 2): if all(map(lambda x:i%x, primes)): primes.append(i) return primes def

Adding wheel factorization to an indefinite sieve

♀尐吖头ヾ 提交于 2019-11-26 10:02:20
问题 I’m modifying an indefinite sieve of Eratosthenes from here so it uses wheel factorization to skip more composites than its current form of just checking all odds. I’ve worked out how to generate the steps to take to reach all the gaps along the wheel. From there I figured I could just substitute the +2’s for these wheel steps but it’s causing the sieve to skip primes. Here\'s the code: from itertools import count, cycle def dvprm(end): \"finds primes by trial division. returns a list\"