OFFSET
1,1
COMMENTS
For the sequence to be infinite no term can be a prime except for a(1) = 2. One can show that if a(n) is a prime p, then the only possible value for a(n-1) is 2p or p + p^2 since, if a term is prime, the preceding term must be a multiple of that prime. However the preceding term cannot be 2p since the difference between the terms would then be prime, therefore it must be p + p^2. However the only possible value for the term after a prime p is likewise p + p^2, but that has already been used, thus allowing a term to be prime would terminate the sequence.
LINKS
Scott R. Shannon, Table of n, a(n) for n = 1..10000.
Michael De Vlieger, Log log scatterplot of a(n) n = 1..1024, showing prime powers in gold, squarefree numbers in green, and numbers neither squarefree nor prime powers in blue, highlighting powerful numbers that are not prime powers in light blue.
EXAMPLE
a(9) = 4 as |4 - a(8)| = |4 - 12| = 8, and 8 is a divisor of 4*12 = 48 and is not a prime. Note that |3 - 12| = 9 is a divisor of 3*12 = 36 and is not a prime, but as shown above a prime term will terminate the sequence so is not permitted.
MATHEMATICA
nn = 120; c[_] := False; s = {2, 6};
f[x_] := Times @@ FactorInteger[x][[All, 1]];
MapIndexed[Set[{a[First[#2]], c[#1]}, {#1, True}] &, s];
Set[{j, u}, {s[[-1]], 4}];
Do[k = u;
While[Or[c[k], #1 < 4, PrimeQ[#1],
! Divisible[j*k, #1], ! Divisible[j, #2], ! Divisible[k, #2]] & @@
{#, f[#]} &@ Abs[j - k], k++];
Set[{a[n], c[k], j}, {k, True, k}];
If[k == u, While[Or[c[u], PrimeQ[u]], u++]], {n, Length[s] + 1, nn}];
Array[a, nn] (* Michael De Vlieger, Sep 29 2023 *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Scott R. Shannon, Sep 27 2023
STATUS
approved