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


Groups > sci.math > #331262

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 08:32 -0700
Organization Aioe.org NNTP Server
Message-ID <ndu1f2$2fo$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 found an interesting pattern, that allows an easy way to find all
the coprimes of primorial 2310, given primorial 210 coprimes.

It is probably generalized for all primorials, so could be used
recursively to find a primorials coprimes, by incrementing
through primorials 6,30,210,2310, etc up to the primorial of
interest, to find that primorials coprimes without doing much
math.

So the description of how it works:

take numbers 1 to 210 and arrange into a single row of
210 columns, then label the columns in that row that are
coprimes of 210.

primorial 210 coprimes (count 48): 
1,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,
121,127,131,137,139,143,149,151,157,163,167,169,173,179,181,187,191,193,197,199,209,

Next extend the single row into a total of 11 rows with row1 counting
from 1 to 210, row2 from 211 to 420, row3 from 421 to 630 etc all the
way to 2310 at the end of the last row11.  This makes a table of 210
columns and 11 rows (2310 numbers total)

Now all possible coprimes for primorial 2310 (a total of 480 coprimes)
will be in the 48 columns that were previously labelled as coprimes
of primorial 210.  There are 11 rows and 48 columns, so that is 11
more numbers than primorial 2310 has coprimes, and accordingly each
column has a single extra number that isn't a coprime of primorial 2310.

There is a pattern to find these numbers that aren't coprimes too,
I didn't figure out where exactly the pattern is coming from but
it is there.

The pattern to find the single number in each of the 48 columns there
is a formula to find which row the number will be in, from row1 to row
11.  You just need to know the location of a single number that isn't
coprime and then you can find all the rest.

Here is the pattern! :D

Given the location of a single number that isn't coprime, in column1,
which is number 2101 in row11, check the gap to the next column
that has coprimes, ie column11, that is a gap of 10 columns (11-1),
so the number that isn't coprime with 2310 in column11 is in 11-10=row1.
11-10 comes from the column1 row 11 minus column11 row 1.

That one is a bit hard to see because of the numbers, but the next
one is easier to see:

The next column that has coprimes is column13 and it has a gap of 13-11
=2 from the last column that has coprimes, so the row position of the
number that isn't a coprime is the last columns row that isn't coprime
minus 2.  The previous column row location that isn't coprime is row1,
so minus 2 rows takes the next row to row 10, the second last row.

Ok that one is hard to see too since there is a row overflow in that
example, but this next example is easier to see!

The next column that has coprimes is column17 and it has a gap of
17-13=4 from the last column that has coprimes.  The previous column's
row location that isn't coprime is row 10, so 10-4=6 means that the
column17 row location of the number that isn't coprime is row6, and
that is number 1067.

There is a single number that isn't coprime in each of the columns,
and after finding them all the table can be turned back into a single
list of numbers to be used to construct a longer table for the next
bigger primorial and the process repeated of removing one non-coprime
from each column that has coprimes.

I didn't test this pattern for other primorials so I am sure it may
vary somewhat, for primorial210 with 30 columns I didn't figure out
the pattern if there even is one.

Also if a fixed width table is used rather than increasing the width
for bigger primorials, there seems to be an interesting pattern of
how to remove non coprimes too, as multiples of prime numbers in
the coprime rows, for primes of size of the largest prime factor for
the primorial and up the size required for the whole table.

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