Deutsch English Français Italiano |
<vb2if8$1jqts$2@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Vir Campestris <vir.campestris@invalid.invalid> Newsgroups: comp.lang.c++ Subject: Re: OT: Re: Sieve of Erastosthenes optimized to the max Date: Sun, 1 Sep 2024 21:23:04 +0100 Organization: A noiseless patient Spider Lines: 45 Message-ID: <vb2if8$1jqts$2@dont-email.me> References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org> <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> <va09jq$30cvv$1@dont-email.me> <va2ca2$3e60e$1@raubtier-asyl.eternal-september.org> <va2cfr$3e9l1$1@raubtier-asyl.eternal-september.org> <va2hq5$3f1gl$1@dont-email.me> <86v7zn3xwk.fsf@linuxsc.com> <vajji3$2rbid$1@raubtier-asyl.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sun, 01 Sep 2024 22:23:05 +0200 (CEST) Injection-Info: dont-email.me; posting-host="8abda7a42fb8d7e82c244a4b19407a73"; logging-data="1698748"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ViejLjLdD3OKdN4P09XO3SVVKdoOSlI8=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:1X6WuSqdaFSVXLGRvILsXy1pC7o= Content-Language: en-GB In-Reply-To: <vajji3$2rbid$1@raubtier-asyl.eternal-september.org> Bytes: 3366 On 27/08/2024 05:09, Bonita Montero wrote: > Am 26.08.2024 um 21:08 schrieb Tim Rentsch: > >> One motivation for choosing a mod30 representation is being able to >> compute more primes -- almost twice as many. Any machine with 64GB >> of memory should be able to compute primes up to 1.5 trillion. > > You don't need to hold all primes in memory. Just calculate the primes > up to the square root and then you can calculate every segment up to > the maximum from that. So you compute all the primes up to the square root of a larger number. I was cleaning up my odds-only code with a view to posting it, when I had an idea. Take 101 (because I can write things more easily). I want to mark 10201,10302,10403,10504,10605,10706... With odds only that becomes 10201,10403,10605,10807,11009,11211... and as the loop increment is a constant it is nice and fast. With mod30 it isn't a constant, and it hurts to work out the increment. Except... If I mark 10201,13231,16261,19291,22321 with an increment of 30*p, then go back to 10201, add 2p, then increment that by 30 10201 13231 16261 and do that for the other 6 of the 8, my inner loop has a constant increment, and my code is compatible with the mod30 store. That might be quicker. I also have some thoughts over storing the prime as two parts. It's 30m+r, where m is modulus and r remainder. r maps one-for-one into the byte mask, and m is the index. I'm going to waste lots more time on this I can see! Andy