login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

Number of ways to express n in the form 1 +- 2 +- 3 ... +- n.
2

%I #20 Dec 24 2024 22:12:00

%S 1,0,0,1,2,0,0,6,11,0,0,57,103,0,0,615,1131,0,0,7209,13467,0,0,89261,

%T 168515,0,0,1147893,2183943,0,0,15181540,29055149,0,0,205171534,

%U 394497990,0,0,2820847321,5444272739,0,0,39329485312,76142226498,0,0,554756557011

%N Number of ways to express n in the form 1 +- 2 +- 3 ... +- n.

%C a(n) is the coefficient of x^(n*(n+3)/4-1) of Product_{k=2..n} (1+x^k). - _Jianing Song_, Nov 19 2021

%H Jianing Song, <a href="/A348639/b348639.txt">Table of n, a(n) for n = 1..1000</a>

%o (C)

%o int solsN(int n, int k, int sum) { if (n == k) return sum == n; return solsN(n, k+1, sum + k + 1) + solsN(n, k+1, sum - k - 1);}

%o int getNumber(int n) { return solsN(n, 1, 1); }

%o (Python)

%o from functools import cache

%o @cache

%o def b(t, s, u): # target, sum, upto

%o if u == 1: return int(t == s + 1)

%o return b(t, s - u, u - 1) + b(t, s + u, u - 1)

%o def a(n): return b(n, 0, n)

%o print([a(n) for n in range(1, 49)]) # _Michael S. Branicky_, Oct 29 2021

%o (PARI) list(n) = my(poly=vector(n), v=vector(n)); poly[1]=1; for(k=2, n, poly[k]=poly[k-1]*(1+'x^k)); for(k=1, n, if(k%4==2||k%4==3, v[k]=0, v[k]=polcoeff(poly[k], k*(k+3)/4-1))); v \\ _Jianing Song_, Nov 19 2021

%Y Cf. A000980, A058377.

%K nonn

%O 1,5

%A _Daniel Cortild_, Oct 26 2021

%E a(30)-a(48) from _Michael S. Branicky_, Oct 29 2021