function [M] = A362816(nmax) % Returns the first "nmax" terms of A362816. K=zeros(nmax,1); K(1:2)=[2 2]; for n=3:nmax B=[]; for q=1:floor((n-1)/2) s=n-q; d=K(s)-K(s-q); U=[K(s)]; s=s-q; while s>0 && U(end)-K(s)==d U=[U K(s)]; s=s-q; end F=[U(1)+d U]; if length(F)>min(F) && ~any(B(:)==U(1)+d) B=[B U(1)+d]; end end k=2; while any(B(:)==k) k=k+1; end K(n)=k; end N=1:length(K); M=[N' K]; end