A339557 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.
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, 53, 79, 52, 24, 53, 83, 114, 82, 115, 149, 184, 148, 111, 149, 188, 228, 187, 229, 186, 142, 187, 233, 280, 232, 281, 331, 382, 330, 277, 331, 276, 220, 277, 335, 394, 334, 273, 335, 398, 462, 397
Offset: 0
Keywords
Examples
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. 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.
Links
- Scott R. Shannon, Image of the terms for n=1 to 1000. The peak value is a(999) = 11794.
- Scott R. Shannon, Image of the terms for n=1 to 1000000. The peak value is a(327047) = 149919884.
- Scott R. Shannon, Image of the terms for n=1 to 20000000. 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.
- Scott R. Shannon, Image of the terms for n=1 to 50000000. The peak value is a(37076766) = 1695632131873.
Programs
-
Mathematica
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 *)
Comments