1
$\begingroup$

I am trying to calculate the set of unique differences in a sequence, however the sequence grows fast and I hit the RAM limit of my PC for nthPrimeToUse = 11. For nthPrimeToUse 1 to 10 the output of Length[abc4] is: 0,1,2,3,5,7,10,13,16,20,... I am trying to find at least a few more terms if possible. Here is the code:

Updated code: (outputs: 0,1,2,3,5,7,10,13,16,20 for nthPrimeToUse=1 to 10)

nthPrimeToUse = 5; 
primeNumber = Prime[nthPrimeToUse];
Primorial[n_] := Times @@ Prime[Range[n]]
PrimorialToUse = Primorial[nthPrimeToUse - 1];
range = PrimorialToUse*primeNumber*2;
x = Select[(primeNumber) Range@range, GCD[#, PrimorialToUse ] == 1 &];
x = x/primeNumber;
valuesDivisibleByPrime = {}
For[i = 0, i < Length[x], i++,
 If[GCD[x[[i]], primeNumber] != 1,
  AppendTo[valuesDivisibleByPrime, x[[i]]]
  ]
 ]
x = Differences[valuesDivisibleByPrime] ;
CountDistinct[x]

This code is faster, possibly equivalent to the above code for nthPrimeToUse > 3 (outputs: 0,0,1,3,5,7,10,13,16,20 for nthPrimeToUse=1 to 10)

nthPrimeToUse = 5;
primeNumber = Prime[nthPrimeToUse];
Primorial[n_] := Times @@ Prime[Range[n]]
PrimorialToUse = Primorial[nthPrimeToUse - 1];

coprimesOfPrimorial = 
  Select[Range[1, PrimorialToUse], CoprimeQ[PrimorialToUse, #] &];
abc1 = Length[coprimesOfPrimorial];
abc2 = Differences[coprimesOfPrimorial];
abc3 = CountDistinct[abc2];
abc4 = DeleteDuplicates[abc2];
abc4 = abc4*primeNumber;
Sort[abc4]
Length[abc4]

Thanks.

cheers, Jamie

$\endgroup$
  • 1
    $\begingroup$ Maybe it's a known sequence? OEIS has 7 suggestions. $\endgroup$ – Roman Jul 5 at 21:11
  • $\begingroup$ Hi, none of them seemed likely to be the right sequence, but may need 3 terms to know. I guess partitioning the sequence and then checking the partitions could save RAM. $\endgroup$ – Jamie M Jul 5 at 21:35
  • 1
    $\begingroup$ Try asking on Math.SE for a closed form; it seems like there should be one. $\endgroup$ – lirtosiast Jul 6 at 5:14
  • $\begingroup$ Thanks, I asked the question here: math.stackexchange.com/questions/3284736/… $\endgroup$ – Jamie M Jul 6 at 7:11
  • 2
    $\begingroup$ When I execute your code I get the sequence $\{0, 0, 1, 3, 5, 7, 10, 13, 16,\ldots\}$. What are the correct values for $n=1,2,3$? $\endgroup$ – Roman Jul 6 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.