OFFSET
1,2
COMMENTS
A somehow "trivial" variant of A133058 and A255140, both of which have very similar definitions, but enter 4-periodic loops only at later indices.
There could be two motivated values for an initial term: either a(0)=0 which would yield a(1)=1 and the following values via the recursion formula, or a(0)=2 according to the general formula for a(4k).
LINKS
Index entries for linear recurrences with constant coefficients, signature (0,0,0,2,0,0,0,-1).
FORMULA
a(4k+1) = 1, a(4k+2) = 4k+3, a(4k+3) = 2*a(4k+2) = 8k+6, a(4k) = 2.
G.f.: x*(1 + 3*x + 6*x^2 + 2*x^3 - x^4 + x^5 + 2*x^6 - 2*x^7)/((1 - x)^2*(1 + x)^2*(1 + x^2)^2). - Bruno Berselli, Feb 16 2015
a(n) = ( 2*(3 + (-1)^n) - (2 - 3*n + n*(-1)^n)*(1 - (-1)^((n-1)*n/2)) )/4. - Bruno Berselli, Feb 16 2015
EXAMPLE
a(2) = a(1)+2 = 3, a(3) = a(2)+3 = 6, a(4) = a(3)/3 = 2, a(5) = a(4)/2 = 1;
a(6) = a(5)+6 = 7, a(7) = a(6)+7 = 14, a(8) = a(7)/7 = 2, a(9) = a(8)/2 = 1; ...
MATHEMATICA
Table[(2 (3 + (-1)^n) - (2 - 3 n + n (-1)^n) (1 - (-1)^((n - 1) n/2)))/4, {n, 1, 80}] (* Bruno Berselli, Feb 16 2015 *)
nxt[{n_, a_}]:={n+1, If[GCD[a, n]>1, a/GCD[a, n], a+n+1]}; Transpose[ NestList[ nxt, {1, 1}, 80]][[2]] (* or *) LinearRecurrence[{0, 0, 0, 2, 0, 0, 0, -1}, {1, 3, 6, 2, 1, 7, 14, 2}, 80] (* Harvey P. Dale, Oct 13 2015 *)
PROG
(PARI) (A255051_upto(N)=vector(N, n, if(gcd(N, n-1)>1, N\=gcd(N, n-1), N+=n)))(99) \\ simplified by M. F. Hasler, Jan 11 2020
(PARI) A255051(n)=if(n%4>1, if(bittest(n, 0), n*2, n+1), 2-bittest(n, 0)) \\ M. F. Hasler, Feb 18 2015
(Magma) &cat [[1, 4*n+3, 8*n+6, 2]: n in [0..20]]; // Bruno Berselli, Feb 16 2015
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
M. F. Hasler, Feb 15 2015
STATUS
approved