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


Groups > sci.math > #331252

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-04 02:20 -0700
Organization Aioe.org NNTP Server
Message-ID <ndtbju$q91$1@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:
> On Wed, 30 Mar 2016 23:27:21 -0700, Jamie M wrote:
>> On 3/30/2016 10:22 PM, James Waldby wrote:
>>> On Wed, 30 Mar 2016 16:42:18 -0700, Jamie M wrote:
>>> ...
>>>> What I'm interested to find out about is if I can get a formula to
>>>> find the sequence of coprimes for a primorial.
>>>>
>>>> ie for primorial 30 the coprimes:   1,7,11,13,17,19,23,29
>>>>
>>>> EulerPhi(30) is the count of coprimes but I'd like to get the
>>>> formula to find the actual coprimes.  Any idea?
>>>>
>>>> I want to find the coprimes of very large primorials efficiently..
>>>
>>> I don't know of a formula.  It's possible that the following process
> [snip algorithm that sets bits in a map]
>>>
>>
>> Thanks, right now I just generate a big list of primes and
>> then check all numbers below the primorial to see if they
>> are coprime with the primorial, not as fast maybe but I ran
>> it up to primorial 223092870 now giving this result:
>
> For the purpose of listing gaps between consecutive coprimes, that
> method seems reasonable enough, except there's no need to make a big
> list of primes, and you might be able to speed up the coprimeness
> check by the method illustrated in a demo program included below.
> It shows a way of using reciprocals to test if n is a multiple of p
> in {5, 7, 11, 13, 17, 19, 23}.  On my computer the method runs about
> twice as fast as testing if n%p is zero for some p in that set.  The
> program prints out the following result, where the first line is for
> the reciprocals method and the second line is for the modulus method.
>
>     ncr = 36495360 for tmax = 223092870 in  0.309669 seconds
>
>     nco = 36495360 for tmax = 223092870 in  0.588192 seconds
>
>> primorial 223092870 coprime equation list gap counts: (36495360 total)
>>
>> gap count
>> {[2, 7952175]}
>> {[4, 7952175]}
> [snip rest of list]
>>
>> There should be more ways to optimize finding the coprimes
>> of primorials, as for one, they are a palindrome, so only
>
>     Rather than saying "they are a palindrome" you should say
>     they are located in symmetric pairs.
>
>> the first half need to be found to fill in the locations
>> of the second half, but I think there are more ways to
>> figure out where they are too.
>
> 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;
> }
>


Hi,

I think there is a formula to do this too, based on a thing I noticed
before that was answered with a way to find the primorial coprimes:

I found this pattern:

Primorial primefactors coprimes
2 2
6 2x3 2
30 6x5 8 ((5-1)*2)
210 30x7 48 ((7-1)*8)
2310 210x11 480 ((11-1)*48)

There is the primes-1 sequence in there for the coprimes formula,
ie to get EulerPhi(2310)=480 it is (11-1)*48

Question: how do you explain coprimes being
(nextprimefactor-1)*(coprimes of next smallest primorial)?


And got a reply for a formula from a poster in the thread
"what is this pattern in the primes" on sci.electronics.design:


//reply answer

Write the numbers from 1 to your current primorial. If that's 6, then 
you have

1 2 3 4 5 6

Now remove the numbers that are divisible by the factors

1 X X X 5 X

Now consider your next primorial, which is given by multiplying the 
current by the next prime, p.

Create p - 1 new lines by adding your current primorial to each number, 
successively:

  1 X X X  5 X
  7 X X X 11 X
13 X X X 17 X
19 X X X 23 X
25 X X X 29 X

Now, this contains all the numbers from 1 to the new primorial, with the 
multiples of the current primorial's factors already removed.

Since the previous primorial is coprime with the new factor p, each 
column that hasn't already been removed contains exactly one number that 
is divisible by p. We can rearrange the columns to put that number last, 
then remove the entirety of the last row.

  1 X X X 11 X
  7 X X X 17 X
13 X X X 23 X
19 X X X 29 X

So the count of numbers remaining (being the coprime count for the next 
primorial) is (p-1) * the count of numbers in the first row (being the 
coprime count for the current primorial).

Sylvia.

//end of reply answer



So I think it is really easy to find the list of coprimes for a given
primorial using that?! :)

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