A386437 Alternating sum of the numbers in the trajectory of n for the 3x+1 problem.
1, 1, -13, 3, -6, 19, -24, 5, 19, 16, -9, -7, -23, 38, -212, 11, 14, -1, -85, 4, -22, 31, -181, 31, 72, 49, -21488, -10, -46, 242, 21412, 21, -89, 20, -134, 37, -9, 123, -104, 36, -21433, 64, -104, 13, -43, 227, 21475, 17, -16, -22, -246, 3, -63, 21542, 21040, 66, 75, 104
Offset: 1
Examples
a(3) = 3 - 10 + 5 - 16 + 8 - 4 + 2 - 1 = -13.
Links
Programs
-
Maple
a:= proc(n) option remember; n-`if`(n=1, 0, a(`if`(n::even, n/2, 3*n+1))) end: seq(a(n), n=1..58); # Alois P. Heinz, Jul 24 2025
-
Mathematica
a[n_] := Module[{x = n, seq = {n}},While[x != 1, x = If[EvenQ[x], x/2, 3 x + 1]; AppendTo[seq, x]];Total[seq*Table[(-1)^i, {i, 0, Length[seq] - 1}]]]Table[a[n], {n, 1, 60}]
-
PARI
a(n) = my(s=n, m=n, k=-1); while (m != 1, if (m%2, m=3*m+1, m=m/2); s+=k*m; k=-k); s; \\ Michel Marcus, Jul 25 2025
Comments