login
A342131
a(n) = n/2 + floor(n/4) if n is even, otherwise (3*n+1)/2.
3
0, 2, 1, 5, 3, 8, 4, 11, 6, 14, 7, 17, 9, 20, 10, 23, 12, 26, 13, 29, 15, 32, 16, 35, 18, 38, 19, 41, 21, 44, 22, 47, 24, 50, 25, 53, 27, 56, 28, 59, 30, 62, 31, 65, 33, 68, 34, 71, 36, 74, 37, 77, 39, 80, 40, 83, 42, 86, 43, 89, 45, 92, 46, 95, 48, 98, 49, 101, 51, 104
OFFSET
0,2
COMMENTS
A permutation of the nonnegative integers related to the Collatz function (A014682).
Interspersion of A032766 and A016789. - Michel Marcus, Mar 04 2021
FORMULA
a(n) = 9*n - 2*a(n-1) - 2*a(n-2) - 2*a(n-3) - a(n-4) - 17 for n >= 4.
a(n) = a(n-2) + a(n-4) - a(n-6).
a(n) = A006368(n+1) - 1.
G.f.: (x^4+2*x^3+3*x^2+x+2)*x/((x^2+1)*(x-1)^2*(x+1)^2). - Alois P. Heinz, Mar 01 2021
E.g.f.: (cos(x) + (6*x - 1)*cosh(x) + (2 + 3*x)*sinh(x))/4. - Stefano Spezia, Mar 02 2021
From Bruno Berselli, Mar 05 2021: (Start)
a(n) = (12*n + 4 - (3*n + 3 - (-1)^(n/2))*(1 + (-1)^n))/8. Therefore:
a(4*k) = 3*k;
a(4*k+1) = 6*k + 2;
a(4*k+2) = 3*k + 1;
a(4*k+3) = 6*k + 5. (End)
MATHEMATICA
a[n_] := If[EvenQ[n], n/2 + Floor[n/4], (3*n + 1)/2]; Array[a, 100, 0] (* Amiram Eldar, Mar 03 2021 *)
Table[(12 n + 4 - (3 n + 3 - (-1)^(n/2)) (1 + (-1)^n))/8, {n, 0, 70}] (* Bruno Berselli, Mar 05 2021 *)
PROG
(MATLAB)
function [a] = A342131(max_n)
for n = 1:max_n
m = n-1;
if floor(m/2) == m/2
a(n) = (m/2)+floor(m/4);
else
a(n) = (m*3+1)/2;
end
end
end
(PARI) a(n) = if (n%2, (3*n+1)/2, n/2 + n\4); \\ Michel Marcus, Mar 04 2021
(Magma) &cat [[3*k, 6*k+2, 3*k+1, 6*k+5]: k in [0..20]] // Bruno Berselli, Mar 05 2021
(Python)
def A342131(n): return (3*n+1)//2 if n % 2 else n//2+n//4 # Chai Wah Wu, Mar 05 2021
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Thomas Scheuerle, Mar 01 2021
STATUS
approved