cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A004978 a(n) = least integer m > a(n-1) such that m - a(n-1) != a(j) - a(k) for all j, k less than n; a(1) = 1, a(2) = 2.

This page as a plain text file.
%I A004978 N0416 #54 Sep 01 2025 11:35:04
%S A004978 1,2,4,8,13,21,31,45,60,76,97,119,144,170,198,231,265,300,336,374,414,
%T A004978 456,502,550,599,649,702,759,819,881,945,1010,1080,1157,1237,1318,
%U A004978 1401,1486,1572,1662,1753,1845,1945,2049,2156,2264,2380,2499,2623,2750,2882
%N A004978 a(n) = least integer m > a(n-1) such that m - a(n-1) != a(j) - a(k) for all j, k less than n; a(1) = 1, a(2) = 2.
%C A004978 Equivalently, if S(n) = { a(j) - a(k); n > j > k > 0 }, then a(n) = a(n-1) + M where M = min( {1, 2, 3, ...} \ S(n) ) is the smallest positive integer not in S(n). - _M. F. Hasler_, Jun 26 2019
%D A004978 N. J. A. Sloane, A Handbook of Integer Sequences, Academic Press, 1973 (includes this sequence).
%H A004978 Chai Wah Wu, <a href="/A004978/b004978.txt">Table of n, a(n) for n = 1..10000</a> (terms 1..2000 from Nathaniel Johnston)
%H A004978 G. E. Andrews, <a href="http://www.jstor.org/stable/2318498">MacMahon's prime numbers of measurement</a>, Amer. Math. Monthly, 82 (1975), 922-923.
%e A004978 From _M. F. Hasler_, Jun 26 2019: (Start)
%e A004978 After a(1) = 1, a(2) = 2, we have a(3) = least m > a(2) such that m - a(2) = m - 2 is not in { a(j) - a(k); 1 <= k < j < 3 } = { a(2) - a(1) } = { 1 }. Thus we must have m - 2 = 2, whence m = 4.
%e A004978 The next term a(4) is the least m > a(3) such that m - a(3) = m - 4 is not in { a(j) - a(k); 1 <= k < j < 4 } = { 1, 4 - 2 = 2, 4 - 1 = 3 }, i.e., m = 4 + 4 = 8.
%e A004978 The next term a(5) is the least m > a(4) such that m - a(4) = m - 8 is not in { a(j) - a(k); 1 <= k < j < 5 } = { 1, 2, 3, 8 - 4 = 4, 8 - 2 = 6, 8 - 1 = 7 }, i.e., m = 5 + 8 = 13. (End)
%o A004978 (MATLAB) s=1:2000^2;d(1)=1;A004978(1)=1;A004978(2)=2;
%o A004978 for n=3:2000
%o A004978   A004978(n)=A004978(n-1)+find([d,0]~=s(1:max(size(d))+1),1);
%o A004978   d(end+1:end+n-1)=A004978(n)-A004978(1:n-1);
%o A004978   d=sort(unique(d));
%o A004978 end
%o A004978 % _Nathaniel Johnston_, Feb 09 2011
%o A004978 (PARI) A004978_vec(N,a=[1..N],S=[1])={for(n=3,N,a[n]=a[n-1]+S[1]+1;S=setunion(S,select(t->t>S[1],vector(n-1,k,a[n]-a[n-k])));for(k=1,#S-1, if(S[k+1]-S[k]>1, S=S[k..-1];next(2)));S[#S]==#S&&S=[#S]);a} \\ _M. F. Hasler_, Jun 26 2019
%o A004978 (Python)
%o A004978 from itertools import count, accumulate, islice
%o A004978 from collections import deque
%o A004978 def A004978_gen(): # generator of terms
%o A004978     aset, alist, c = set(), deque(), 1
%o A004978     for k in count(1):
%o A004978         if k in aset:
%o A004978             aset.remove(k)
%o A004978         else:
%o A004978             yield c
%o A004978             aset |= set(k+d for d in accumulate(alist))
%o A004978             alist.appendleft(k)
%o A004978             c += k
%o A004978 A004978_list = list(islice(A004978_gen(),20)) # _Chai Wah Wu_, Sep 01 2025
%Y A004978 Differences give A002048, see also A048201.
%Y A004978 See also A001856.
%Y A004978 For n>2, a(n) equals A002049(n-1)+1 and A048204(n-2)+2.
%K A004978 nonn,changed
%O A004978 1,2
%A A004978 _N. J. A. Sloane_. This was in the 1973 "Handbook", but was then dropped from the database. Resubmitted by _Clark Kimberling_. Entry revised by _N. J. A. Sloane_, Jun 10 2012
%E A004978 Definition corrected by Bryan S. Robinson, Mar 16 2006
%E A004978 Name edited by _M. F. Hasler_, Jun 26 2019