OFFSET
1,2
COMMENTS
This is very nearly a linear recurrence, but the distinctness requirement occasionally foils it. - Charles R Greathouse IV, Nov 07 2014
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..10000
FORMULA
a(2*n-1) = n^2; a(2*n) = n*(2+5*n). Also, (1/(2*n))*(Sum_{i=1..n} i^2 + i*(2+5*i)) = (n+1)^2 and (1/(2*n-1))*(Sum_{i=1..n} i^2 + (i-1)*(5*i-3)) = k^2. Thus the arithmetic mean of the first 2*n terms is (n+1)^2 and the arithmetic mean of the first 2*n-1 terms is n^2. - Derek Orr, Jun 26 2015
EXAMPLE
(a(1) + a(2) + a(3) + a(4) + a(5))/5 = (1+7+4+24+9)/5 = 9 = 3^2.
MAPLE
b:= proc(n) is(n>1) end:
s:= proc(n) option remember;
`if`(n=1, 1, s(n-1)+a(n))
end:
a:= proc(n) option remember; local k;
if n=1 then 1
else for k from n-irem(s(n-1), n) by n
do if b(k) and issqr((s(n-1)+k)/n)
then b(k):=false; return k
fi
od
fi
end:
seq(a(n), n=1..150); # Alois P. Heinz, Nov 07 2014
MATHEMATICA
Clear[a, b, s]; b[n_] := n>1; s[n_] := s[n] = If[n == 1, 1, s[n-1] + a[n]]; a[n_] := a[n] = Module[{k}, If [n == 1, 1, For[k = n - Mod[s[n-1], n], True, k = k+n, If[b[k] && IntegerQ[Sqrt[(s[n-1]+k)/n]], b[k] = False; Return[k]]]]]; Table[a[n], {n, 1, 150}] (* Jean-François Alcover, Jun 10 2015, after Alois P. Heinz *)
PROG
(PARI) v=[1]; n=1; while(#v<50, s=(n+vecsum(v))/(#v+1); if(type(s)=="t_INT", if(issquare(s)&&!vecsearch(vecsort(v), n), v=concat(v, n); n=0)); n++); v \\ Derek Orr, Nov 05 2014, edited Jun 26 2015
CROSSREFS
KEYWORD
nonn
AUTHOR
Amarnath Murthy, Jun 20 2003
EXTENSIONS
More terms from David Wasserman, Jan 11 2005
Incorrect formulas and programs removed by Charles R Greathouse IV, Nov 07 2014
STATUS
approved