A386883 Define a sequence of rationals by f(0) = 0, thereafter f(n) = f(n-1) - 1/n if that is >= 0, otherwise f(n) = f(n-1) + 1/n; a(n) corresponds to the number of addition steps minus the number of subtraction steps involved in calculating f(n).
0, 1, 0, -1, 0, -1, -2, -1, -2, -1, -2, -1, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -2, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3, -4, -3
Offset: 0
Examples
Sequence begins: n a(n) f(n)-f(n-1) -- ---- ----------- 0 0 N/A 1 1 +1 2 0 -1/2 3 -1 -1/3 4 0 +1/4 5 -1 -1/5 6 -2 -1/6 7 -1 +1/7 8 -2 -1/8 9 -1 +1/9 10 -2 -1/10 11 -1 +1/11 12 -2 -1/12 13 -3 -1/13 14 -2 +1/14 15 -3 -1/15
Links
- Rémy Sigrist, Table of n, a(n) for n = 0..10000
Programs
-
Mathematica
Module[{f = 0, a = 0}, Array[If[f >= 1/#, f -= 1/#; a--, f += 1/#; a++] &, 100]] (* Paolo Xausa, Aug 25 2025 *)
-
PARI
{ print1(0); f = 0; a = 0; for (n = 1, 65, if (f >= 1/n, f -= 1/n; a--, f += 1/n; a++); print1 (", "a);); }
Comments