login
a(n) is the least number not already used such that the arithmetic mean of the first n terms is a square.
3

%I #31 Apr 11 2019 22:04:03

%S 1,7,4,24,9,51,16,88,25,135,36,192,49,259,64,336,81,423,100,520,121,

%T 627,144,744,169,871,196,1008,225,1155,256,1312,289,1479,324,1656,361,

%U 1843,400,2040,441,2247,484,2464,529,2691,576,2928,625,3175,676,3432,729

%N a(n) is the least number not already used such that the arithmetic mean of the first n terms is a square.

%C This is very nearly a linear recurrence, but the distinctness requirement occasionally foils it. - _Charles R Greathouse IV_, Nov 07 2014

%H Alois P. Heinz, <a href="/A085047/b085047.txt">Table of n, a(n) for n = 1..10000</a>

%F 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

%e (a(1) + a(2) + a(3) + a(4) + a(5))/5 = (1+7+4+24+9)/5 = 9 = 3^2.

%p b:= proc(n) is(n>1) end:

%p s:= proc(n) option remember;

%p `if`(n=1, 1, s(n-1)+a(n))

%p end:

%p a:= proc(n) option remember; local k;

%p if n=1 then 1

%p else for k from n-irem(s(n-1),n) by n

%p do if b(k) and issqr((s(n-1)+k)/n)

%p then b(k):=false; return k

%p fi

%p od

%p fi

%p end:

%p seq(a(n), n=1..150); # _Alois P. Heinz_, Nov 07 2014

%t 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_ *)

%o (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

%Y Cf. A168668.

%K nonn

%O 1,2

%A _Amarnath Murthy_, Jun 20 2003

%E More terms from _David Wasserman_, Jan 11 2005

%E Incorrect formulas and programs removed by _Charles R Greathouse IV_, Nov 07 2014