Deutsch English Français Italiano |
<va8jfa$k5pk$1@redfloyd.dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!redfloyd.dont-email.me!.POSTED!not-for-mail From: red floyd <no.spam.here@its.invalid> Newsgroups: comp.lang.c++ Subject: Re: OT: Re: Sieve of Erastosthenes optimized to the max Date: Thu, 22 Aug 2024 17:00:42 -0700 Organization: A noiseless patient Spider Lines: 31 Message-ID: <va8jfa$k5pk$1@redfloyd.dont-email.me> References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org> <utoh9d$6lrr$1@raubtier-asyl.eternal-september.org> <utq0ag$hvrl$3@dont-email.me> <utq0os$ibqn$1@raubtier-asyl.eternal-september.org> <utq11p$icmm$1@dont-email.me> <v25c87$1ld9m$1@dont-email.me> <86r0duwqgg.fsf@linuxsc.com> <v39o3l$1lvju$1@dont-email.me> <86o78mpnlf.fsf@linuxsc.com> <v3fv2u$2ursd$1@dont-email.me> <86ttibod7n.fsf@linuxsc.com> <86h6eaoi2r.fsf@linuxsc.com> <v4sool$1grge$1@dont-email.me> <867celixcw.fsf@linuxsc.com> <v5sg9s$mat4$1@dont-email.me> <86zfr0b9hw.fsf@linuxsc.com> <v638ud$25623$1@dont-email.me> <861q3o5do1.fsf@linuxsc.com> <v7tdts$29195$1@dont-email.me> <868qx45v5g.fsf@linuxsc.com> <v9lbns$11alj$1@dont-email.me> <86r0aojx1m.fsf@linuxsc.com> <v9o2kf$1gqv1$1@raubtier-asyl.eternal-september.org> <va88m0$ikl3$2@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 23 Aug 2024 02:00:42 +0200 (CEST) Injection-Info: redfloyd.dont-email.me; posting-host="d56d95f4aa16b703b53ae131c789982b"; logging-data="661300"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/GFB9M2t2dYLBBr+dmJAQm2yv5deytl1U=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:AHAq6IUQwdkGSxTeK5zDob7vqmw= In-Reply-To: <va88m0$ikl3$2@dont-email.me> Content-Language: en-US Bytes: 2996 On 8/22/2024 1:56 PM, Vir Campestris wrote: > On 16/08/2024 18:35, Bonita Montero wrote: >> But basically I don't think it is a good idea to skip numbers exept >> multiples of two. With the three you save a sixth of memory, with >> the five you save a 15-th and at the end you get about 20% less >> storage (1 / (2 * 3) + 1 / (2 * 3 * 5) + 1 / (2 * 3 * 5 * 7) ...) >> for a lot of computation. That's the point where I dropped this >> idea and I think this extra computation is higher than the time >> for the saved memory loads. > > I've been running some experiments. > > Skipping evens only is nice and simple on computation; that's good. > > Skipping something else requires table lookups. I've knocked up some > code that uses the correct table for skipping primes (but not for mask > bit selection) and run it for 2*3*5, 2*3*5*7, and 2*3*5*7*11. > You can skip multiples of three, by starting with 7, and then alternately adding 4 then 2. e.g. incr = 2; for (val = 7 ; val < MAX_PRIME_TO_CHECK ; val += incr) { check_for_prime(val); incr = 6 - incr; }