Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Waldby <not@valid.invalid> |
|---|---|
| Newsgroups | sci.math |
| Subject | Re: gaps in coprimes of primorials |
| Date | 2016-04-01 02:27 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <ndkma0$2ne$7@dont-email.me> (permalink) |
| References | (5 earlier) <ndheuo$2ne$3@dont-email.me> <ndhfb4$2ne$4@dont-email.me> <ndho8k$19pc$2@gioia.aioe.org> <ndic6c$2ne$5@dont-email.me> <ndig05$361$1@gioia.aioe.org> |
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;
}
--
jiw
Back to sci.math | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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