login
a(0) = 0, a(1) = 1; for n > 1, a(n) = a(n-1) - n if a(n) is nonnegative, not already in the sequence, and gcd(a(n-1),n) > 1 or gcd(a(n-2),n) = 1. Otherwise a(n) = a(n-1) + n.
2

%I #25 Jan 09 2021 22:45:45

%S 0,1,3,6,2,7,13,20,12,21,31,42,30,17,31,16,32,15,33,14,34,55,77,54,78,

%T 53,79,52,24,53,83,114,82,115,149,184,148,111,149,188,228,187,229,186,

%U 142,187,233,280,232,281,331,382,330,277,331,276,220,277,335,394,334,273,335,398,462,397

%N a(0) = 0, a(1) = 1; for n > 1, a(n) = a(n-1) - n if a(n) is nonnegative, not already in the sequence, and gcd(a(n-1),n) > 1 or gcd(a(n-2),n) = 1. Otherwise a(n) = a(n-1) + n.

%C This sequence is a variation of the Recamán sequence A005132 where the same rules apply except an additional restriction is added whereby a(n) = a(n-1) - n can occur only if gcd(a(n-1),n) > 1 or gcd(a(n-2),n) = 1, where gcd is the greatest common divisor. This additional restriction is inspired by the selection rules of A336957 and A098550.

%C The sequence shows large variations in its values; the bifurcated pattern typical of the Recamán sequence is present but there are regions where the terms rapidly spike up to huge values only to return to smaller values quickly again. For example after 37 million terms a value of ~1.6*10^12 is reached, but just after 41 million terms values below 10000 are again present. See the linked images.

%C It is unclear if all values are eventually visited; numerous small values like 4 and 5 have not occured after 100 million terms.

%H Scott R. Shannon, <a href="/A339557/a339557_3.png">Image of the terms for n=1 to 1000</a>. The peak value is a(999) = 11794.

%H Scott R. Shannon, <a href="/A339557/a339557.png">Image of the terms for n=1 to 1000000</a>. The peak value is a(327047) = 149919884.

%H Scott R. Shannon, <a href="/A339557/a339557_1.png">Image of the terms for n=1 to 20000000</a>. The peak value is a(9923735) = 808851831874. This is over 5000 times larger than the peak value of the first one million terms, the later being unnoticeable at this scale.

%H Scott R. Shannon, <a href="/A339557/a339557_2.png">Image of the terms for n=1 to 50000000</a>. The peak value is a(37076766) = 1695632131873.

%e a(4) = 2. As gcd(a(3),4) = gcd(6,4) = 2 > 1, and as 6 - 4 = 2 has not occurred previously, a(4) = 2.

%e a(10) = 31. a(9) = 21, and 21 - 10 = 11 has not occurred previously. However as gcd(a(9),10) = gcd(21,10) = 1, and gcd(a(8),10) = gcd(12,10) = 2 > 1, both additional criteria for subtraction fail, thus a(10) = a(9) + 10 = 21 + 10 = 31. This is the first term which differs from the standard Recamán sequence A005132.

%t Block[{a = {0, 1}, k = 1}, Do[AppendTo[a, If[And[# > 0, FreeQ[a, #], Or[GCD[a[[-1]], i] > 1, GCD[a[[-2]], i] == 1 ]], #, a[[-1]] + i] &[a[[-1]] - i]], {i, 2, 10^4}]; a] (* _Michael De Vlieger_, Dec 09 2020 *)

%Y Cf. A005132, A336957, A098550, A165430.

%K nonn

%O 0,3

%A _Scott R. Shannon_, Dec 08 2020