%I #55 Sep 10 2020 14:29:22
%S 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,
%T 28,27,26,25,24,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,63,62,
%U 61,60,59,58,57,56,55,54,53,52,51,50,49,48,95,94,93,92,91,90,89,88,87
%N 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)).
%C Sequence is a permutation of the positive integers.
%C The permutation is self-inverse. Except for fixed points 1, 2, 3 it consists completely of 2-cycles: (4,5), (6,7), (8,11), (9,10), (12,15), (13,14), (16,23), (17,22), ..., (24,31), ..., (32,47), ... . - _Klaus Brockhaus_
%C The permutation transforms enumeration system of positive irreducible fractions A071766/A229742 (HCS) into enumeration system A245325/A245326, and vice versa. - _Yosu Yurramendi_, Jun 09 2015
%C A092569(a(n)) = a(A092569(n)), n > 0.
%C A258746(a(n)) = a(A258746(n)), n > 0.
%C A258996(a(n)) = a(A258996(n)), n > 0.
%C A054429(a(n)) = a(A054429(n)), n > 0.
%C a(n) = A054429(A063946(n)) = A063946(A054429(n)), n > 0. - _Yosu Yurramendi_, Mar 23 2017
%H Robert Israel, <a href="/A117120/b117120.txt">Table of n, a(n) for n = 1..10000</a>
%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%F 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.
%F For n >= 2: a(2*n) = 2*a(n)+1, a(2*n+1) = 2*a(n). - _Yosu Yurramendi_, Jun 08 2015
%p A[1]:= 1: A[2]:= 2: B[1]:= 0: B[2]:= 0:
%p for n from 3 to 100 do
%p for m from A[n-1]-1 by A[n-1] while assigned(B[m]) do od:
%p A[n]:= m;
%p B[m]:= 0;
%p od:
%p seq(A[n],n=1..100); # _Robert Israel_, Jun 09 2015
%t 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 *)
%t 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 *)
%t 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 *)
%o (R)
%o a <- 1:3 # If it were c(1, 3, 2), it would be A054429
%o maxn <- 50 # by choice
%o #
%o for(n in 2:maxn){
%o a[2*n ] <- 2*a[n]+1
%o a[2*n+1] <- 2*a[n]
%o }
%o #
%o a
%o # _Yosu Yurramendi_, Jun 08 2015
%o (PARI) A(n) = if(n<4, n, if(n%2, 2*A(n\2), 2*A(n/2)+1));
%o for(n=1, 50, print1(A(n), ", ")) \\ _Indranil Ghosh_, Mar 21 2017
%Y Cf. A071766, A229742, A245325, A245326.
%K easy,nonn
%O 1,2
%A _Leroy Quet_, Apr 19 2006
%E More terms from _Klaus Brockhaus_