login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A066949
Take the sum of the previous two terms, subtract n if this sum is greater than n.
1
0, 1, 1, 2, 3, 5, 2, 7, 1, 8, 9, 6, 3, 9, 12, 6, 2, 8, 10, 18, 8, 5, 13, 18, 7, 25, 6, 4, 10, 14, 24, 7, 31, 5, 2, 7, 9, 16, 25, 2, 27, 29, 14, 43, 13, 11, 24, 35, 11, 46, 7, 2, 9, 11, 20, 31, 51, 25, 18, 43, 1, 44, 45, 26, 7, 33, 40, 6, 46, 52, 28, 9, 37, 46, 9, 55, 64, 42, 28, 70, 18
OFFSET
0,4
FORMULA
a(n) = a(n-1)+a(n-2)-n if a(n-1)+a(n-2)>n, a(n) = a(n-1)+a(n-2) otherwise; a(0) = 0, a(1) = 1.
MATHEMATICA
a[0] = 0; a[1] = 1; a[n_] := a[n] = Block[ {b = a[n - 1] + a[n - 2]}, If[b > n, Return[b - n], Return[b]]]; Table[a[n], {n, 0, 80} ]
nxt[{n_, a_, b_}]:={n+1, b, If[a+b>n+1, a+b-n-1, a+b]}; Transpose[ NestList[ nxt, {1, 0, 1}, 80]][[2]] (* Harvey P. Dale, Sep 04 2013 *)
PROG
(Haskell)
a066949 n = a066949_list !! n
a066949_list = 0 : 1 : f 2 1 0 where
f k x x' | z > k = (z - k) : f (k+1) (z - k) x
| otherwise = z : f (k+1) z x where z = x + x'
-- Reinhard Zumkeller, Oct 17 2011
(Python)
l=[0, 1]
for n in range(2, 101):
x=l[n - 1] + l[n - 2]
if x>n: l.append(x - n)
else: l.append(x)
print(l) # Indranil Ghosh, Jun 03 2017
CROSSREFS
Cf. A000045.
Sequence in context: A201652 A359609 A272636 * A073481 A178094 A364874
KEYWORD
easy,nonn,nice
AUTHOR
Floor van Lamoen, Jan 25 2002
EXTENSIONS
Edited by Robert G. Wilson v, Jan 31 2002
STATUS
approved