A348639 Number of ways to express n in the form 1 +- 2 +- 3 ... +- n.
1, 0, 0, 1, 2, 0, 0, 6, 11, 0, 0, 57, 103, 0, 0, 615, 1131, 0, 0, 7209, 13467, 0, 0, 89261, 168515, 0, 0, 1147893, 2183943, 0, 0, 15181540, 29055149, 0, 0, 205171534, 394497990, 0, 0, 2820847321, 5444272739, 0, 0, 39329485312, 76142226498, 0, 0, 554756557011
Offset: 1
Keywords
Links
- Jianing Song, Table of n, a(n) for n = 1..1000
Programs
-
C
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);} int getNumber(int n) { return solsN(n, 1, 1); }
-
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
-
Python
from functools import cache @cache def b(t, s, u): # target, sum, upto if u == 1: return int(t == s + 1) return b(t, s - u, u - 1) + b(t, s + u, u - 1) def a(n): return b(n, 0, n) print([a(n) for n in range(1, 49)]) # Michael S. Branicky, Oct 29 2021
Extensions
a(30)-a(48) from Michael S. Branicky, Oct 29 2021
Comments