[go: up one dir, main page]

login
Number of ways of representing n as the sum of one or more consecutive squarefree numbers.
3

%I #28 Feb 07 2023 12:00:27

%S 1,1,2,0,2,2,1,1,0,2,3,0,2,2,1,1,3,1,1,0,3,1,3,2,0,1,1,2,2,1,2,1,2,4,

%T 1,1,1,2,2,1,2,3,2,1,2,2,2,1,1,0,2,1,2,0,4,0,3,2,3,0,3,2,1,1,2,3,2,0,

%U 3,3,3,3,1,1,1,1,2,3,2,2

%N Number of ways of representing n as the sum of one or more consecutive squarefree numbers.

%H Robert Israel, <a href="/A242667/b242667.txt">Table of n, a(n) for n = 1..10000</a>

%e a(6)=2 because n=6 itself is already a squarefree number (sum of 1 term), and 6 can in addition be written as A005117(1)+ A005117(2)+A005117(3), a sum of 3 consecutive squarefree numbers.

%p A242667 := proc(n)

%p a := 0 ;

%p for i from 1 do

%p if A005117(i) > n then

%p return a;

%p end if;

%p for k from i do

%p su := add(A005117(s),s=i..k) ;

%p if su = n then

%p a := a+1 ;

%p elif su > n then

%p break;

%p fi ;

%p end do:

%p end do:

%p end proc:

%p seq(A242667(n),n=1..80) ; # _R. J. Mathar_, Jun 12 2014

%p # Alternative:

%p N:= 1000:# to get the first N entries

%p A005117:= select(numtheory:-issqrfree,[$1..N]):

%p M:= nops(A005117);

%p A:= Array(1..N):

%p t0:= 0:

%p for n from 1 to M-1 do

%p t0:= t0 + A005117[n];

%p t:= t0;

%p for i from 1 while t <= N do

%p A[t] := A[t]+1;

%p if n+i > M then break fi;

%p t:= t + A005117[n+i]-A005117[i];

%p od;

%p od:

%p seq(A[i],i=1..N); # _Robert Israel_, Jun 25 2014

%t With[{N = 100}, (* to get the first N entries *)

%t A005117 = Select[Range[N], SquareFreeQ];

%t M = Length[A005117];

%t A = Table[0, {N}];

%t t0 = 0;

%t For[n = 1, n <= M-1, n++,

%t t0 = t0+A005117[[n]];

%t t = t0;

%t For[i = 1, t <= N, i++,

%t A[[t]] = A[[t]]+1;

%t If[n+i > M, Break[]];

%t t = t + A005117[[n+i]] - A005117[[i]]]

%t ]

%t ];

%t A (* _Jean-François Alcover_, Feb 07 2023, after _Robert Israel_ *)

%Y Cf. A005117.

%K nonn

%O 1,3

%A _Irina Gerasimova_, May 20 2014