Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.math > #331109

Re: gaps in coprimes of primorials

From Jamie M <jmorken@shaw.ca>
Newsgroups sci.math
Subject Re: gaps in coprimes of primorials
Date 2016-04-01 02:48 -0700
Organization Aioe.org NNTP Server
Message-ID <ndlg4i$lsf$3@gioia.aioe.org> (permalink)
References (6 earlier) <ndhfb4$2ne$4@dont-email.me> <ndho8k$19pc$2@gioia.aioe.org> <ndic6c$2ne$5@dont-email.me> <ndig05$361$1@gioia.aioe.org> <ndkma0$2ne$7@dont-email.me>

Show all headers | View raw


On 3/31/2016 7:27 PM, James Waldby wrote:
>
>
> Here's the demo program, in C:
>
> /* Re: Coprimes of primorials
> Copyright 2016 James Waldby.  Offered without warranty
> under GPL v3 terms as at http://www.gnu.org/licenses/gpl.html
> */
> #include <stdlib.h>
> #include <stdio.h>
> #include <sys/time.h>
> //================================================
> double ttime(double base) {
>    struct timeval tod;
>    gettimeofday(&tod, NULL);
>    return tod.tv_sec + tod.tv_usec/1e6 - base;
> }
> //================================================
> int main(int argc, char *argv[]) {
>    double t0, t1;
>    long long B32 = 1LL<<32;
>    unsigned int n, i, nco=0, ncr=0;
>    unsigned int tmax = 223092870;
>    const unsigned int primes[] = {5, 7, 11, 13, 17, 19, 23 };
>    enum { nprimes = sizeof primes / sizeof primes[0] };
>
>    // Use of these "reciprocals" depends on overflow from 32 bit vars
>    unsigned int recips[nprimes];
>    for (i=0; i<nprimes; ++i) {
>      recips[i] = (unsigned int)((B32+primes[i]-1)/primes[i]);
>    }
>    t0=ttime(0);
>    for (n=5; n<tmax; n += 4) {
>      for (i=0; i < nprimes; ++i)
>        if (n*recips[i] < recips[i]) break;
>      if (i==nprimes) ++ncr;
>      n += 2;
>      for (i=0; i < nprimes; ++i)
>        if (n*recips[i] < recips[i]) break;
>      if (i==nprimes) ++ncr;
>    }
>    t1=ttime(t0);
>    printf ("ncr = %d for tmax = %d in %9.6f seconds\n", ncr, tmax, t1);
>
>    t0=ttime(0);
>    for (n=5; n<tmax; n += 4) {
>      for (i=0; i < nprimes; ++i)
>        if (n%primes[i] == 0) break;
>      if (i==nprimes) ++nco;
>      n += 2;
>      for (i=0; i < nprimes; ++i)
>        if (n%primes[i] == 0) break;
>      if (i==nprimes) ++nco;
>    }
>    t1=ttime(t0);
>    printf ("nco = %d for tmax = %d in %9.6f seconds\n", nco, tmax, t1);
>    return 0;
> }
>


Cool thanks for sharing! :)

cheers,
Jamie

Back to sci.math | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

gaps in coprimes of primorials Jamie M <jmorken@shaw.ca> - 2016-03-27 14:50 -0700
  Re: gaps in coprimes of primorials Jamie M <jmorken@shaw.ca> - 2016-03-27 15:00 -0700
    Re: gaps in coprimes of primorials Jamie M <jmorken@shaw.ca> - 2016-03-27 15:20 -0700
      Re: gaps in coprimes of primorials Jamie M <jmorken@shaw.ca> - 2016-03-27 15:47 -0700
        Re: gaps in coprimes of primorials Jamie M <jmorken@shaw.ca> - 2016-03-28 00:56 -0700
          Re: gaps in coprimes of primorials James Waldby <not@valid.invalid> - 2016-03-30 21:03 +0000
            Re: gaps in coprimes of primorials James Waldby <not@valid.invalid> - 2016-03-30 21:09 +0000
              Re: gaps in coprimes of primorials Jamie M <jmorken@shaw.ca> - 2016-03-30 16:42 -0700
                Re: gaps in coprimes of primorials James Waldby <not@valid.invalid> - 2016-03-31 05:22 +0000
                Re: gaps in coprimes of primorials James Waldby <not@valid.invalid> - 2016-03-31 06:17 +0000
                Re: gaps in coprimes of primorials Jamie M <jmorken@shaw.ca> - 2016-03-30 23:27 -0700
                Re: gaps in coprimes of primorials Jamie M <jmorken@shaw.ca> - 2016-03-31 01:11 -0700
                Re: gaps in coprimes of primorials James Waldby <not@valid.invalid> - 2016-04-01 02:27 +0000
                Re: gaps in coprimes of primorials Jamie M <jmorken@shaw.ca> - 2016-04-01 02:48 -0700
                Re: gaps in coprimes of primorials Jamie M <jmorken@shaw.ca> - 2016-04-04 02:20 -0700
                Re: gaps in coprimes of primorials Jamie M <jmorken@shaw.ca> - 2016-04-04 08:32 -0700
                Re: gaps in coprimes of primorials Jamie M <jmorken@shaw.ca> - 2016-04-04 10:27 -0700

csiph-web