A117120 a(1)=1. a(n) is smallest positive integer not occurring earlier in the sequence where a(n) is congruent to -1 (mod a(n-1)).
1, 2, 3, 5, 4, 7, 6, 11, 10, 9, 8, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 31, 30, 29, 28, 27, 26, 25, 24, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 95, 94, 93, 92, 91, 90, 89, 88, 87
Offset: 1
Links
Programs
-
Maple
A[1]:= 1: A[2]:= 2: B[1]:= 0: B[2]:= 0: for n from 3 to 100 do for m from A[n-1]-1 by A[n-1] while assigned(B[m]) do od: A[n]:= m; B[m]:= 0; od: seq(A[n],n=1..100); # Robert Israel, Jun 09 2015
-
Mathematica
f[n_] := Block[{a = {1}, i, k}, Do[k = 1; While[Or[Mod[k, a[[i - 1]]] != a[[i - 1]] - 1, MemberQ[a, k]], k++]; AppendTo[a, k], {i, 2, n}]; a]; f@ 120 (* Michael De Vlieger, Jun 11 2015 *) A[n_]:= If[n<4, n, If[EvenQ[n], 2A[n/2] + 1, 2A[(n - 1)/2]]]; Table[A[n], {n, 100}] (* Indranil Ghosh, Mar 21 2017 *) f[lst_List] := Block[{k = 2, m = lst[[-1]]}, While[ MemberQ[lst, k] || 1 + Mod[k, m] != m, k++]; Append[lst, k]]; Nest[f, {1}, 70] (* Robert G. Wilson v, Jan 22 2018 *)
-
PARI
A(n) = if(n<4, n, if(n%2, 2*A(n\2), 2*A(n/2)+1)); for(n=1, 50, print1(A(n), ", ")) \\ Indranil Ghosh, Mar 21 2017
-
R
a <- 1:3 # If it were c(1, 3, 2), it would be A054429 maxn <- 50 # by choice # for(n in 2:maxn){ a[2*n ] <- 2*a[n]+1 a[2*n+1] <- 2*a[n] } # a # Yosu Yurramendi, Jun 08 2015
Formula
For n >= 2: If a(n-1) = 2^m, m=positive integer, then a(n)= 2^(m+1)-1. If a(n-1) = 3*2^m, m= nonnegative integer, then a(n) = 3*2^(m+1)-1. Otherwise, a(n) = a(n-1) -1.
For n >= 2: a(2*n) = 2*a(n)+1, a(2*n+1) = 2*a(n). - Yosu Yurramendi, Jun 08 2015
Extensions
More terms from Klaus Brockhaus
Comments