A126024
Number of subsets of {1,2,3,...,n} whose sum is a square integer (including the empty subset).
Original entry on oeis.org
1, 2, 2, 3, 5, 7, 12, 20, 34, 60, 106, 190, 346, 639, 1183, 2204, 4129, 7758, 14642, 27728, 52648, 100236, 191294, 365827, 700975, 1345561, 2587057, 4981567, 9605777, 18546389, 35851756, 69382558, 134414736, 260658770, 505941852, 982896850
Offset: 0
The subsets of {1,2,3,4,5} that sum to a square are {}, {1}, {1,3}, {4}, {2,3,4}, {1,3,5} and {4,5}. Thus a(5)=7.
-
import Data.List (subsequences)
a126024 = length . filter ((== 1) . a010052 . sum) .
subsequences . enumFromTo 1
-- Reinhard Zumkeller, Feb 22 2012, Oct 27 2010
-
b:= proc(n, i) option remember; (m->
`if`(n=0 or n=m, 1, `if`(n<0 or n>m, 0, b(n, i-1)+
`if`(i>n, 0, b(n-i, i-1)))))(i*(i+1)/2)
end:
a:= proc(n) option remember; `if`(n<0, 0, a(n-1)+
add(b(j^2-n, n-1), j=isqrt(n)..isqrt(n*(n+1)/2)))
end:
seq(a(n), n=0..50); # Alois P. Heinz, Feb 02 2017
-
g[n_] := Block[{p = Product[1 + z^i, {i, n}]},Sum[Boole[IntegerQ[Sqrt[k]]]*Coefficient[p, z, k], {k, 0, n*(n + 1)/2}]];Array[g, 35] (* Ray Chandler, Mar 05 2007 *)
A284249
Number T(n,k) of k-element subsets of [n] whose sum is a triangular number; triangle T(n,k), n>=0, 0<=k<=n, read by rows.
Original entry on oeis.org
1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 1, 1, 1, 2, 3, 3, 1, 1, 1, 3, 4, 5, 3, 1, 1, 1, 3, 5, 8, 6, 4, 1, 1, 1, 3, 7, 12, 11, 9, 4, 1, 1, 1, 3, 9, 16, 20, 18, 11, 5, 1, 1, 1, 4, 10, 22, 32, 35, 26, 14, 5, 1, 1, 1, 4, 12, 29, 48, 61, 55, 36, 17, 6, 1, 1, 1, 4, 14, 37, 70, 100, 106, 84, 48, 21, 6, 1, 1
Offset: 0
Triangle T(n,k) begins:
1;
1, 1;
1, 1, 1;
1, 2, 1, 1;
1, 2, 2, 1, 1;
1, 2, 3, 3, 1, 1;
1, 3, 4, 5, 3, 1, 1;
1, 3, 5, 8, 6, 4, 1, 1;
1, 3, 7, 12, 11, 9, 4, 1, 1;
1, 3, 9, 16, 20, 18, 11, 5, 1, 1;
1, 4, 10, 22, 32, 35, 26, 14, 5, 1, 1;
1, 4, 12, 29, 48, 61, 55, 36, 17, 6, 1, 1;
1, 4, 14, 37, 70, 100, 106, 84, 48, 21, 6, 1, 1;
Columns k=0-10 give:
A000012,
A003056,
A320848,
A320849,
A320850,
A320851,
A320852,
A320853,
A320854,
A320855,
A320856.
-
b:= proc(n, s) option remember; expand(`if`(n=0,
`if`(issqr(8*s+1), 1, 0), b(n-1, s)+x*b(n-1, s+n)))
end:
T:= n-> (p-> seq(coeff(p, x, i), i=0..n))(b(n, 0)):
seq(T(n), n=0..16);
-
b[n_, s_] := b[n, s] = Expand[If[n == 0, If[IntegerQ @ Sqrt[8*s + 1], 1, 0], b[n - 1, s] + x*b[n - 1, s + n]]];
T[n_] := Function [p, Table[Coefficient[p, x, i], {i, 0, n}]][b[n, 0]];
Table[T[n], {n, 0, 16}] // Flatten (*Jean-François Alcover, May 29 2018, from Maple *)
A339507
Number of subsets of {1..n} whose sum is a decimal palindrome.
Original entry on oeis.org
1, 2, 4, 8, 15, 24, 32, 41, 55, 79, 126, 220, 406, 778, 1524, 3057, 6310, 13211, 27500, 56246, 113003, 224220, 442106, 870323, 1715503, 3391092, 6726084, 13382357, 26686192, 53286329, 106469764, 212803832, 425434124, 850676115, 1701169724, 3402169203, 6804150711, 13608072837, 27215890383, 54431527170
Offset: 0
a(5) = 24 subsets: {}, {1}, {2}, {3}, {4}, {5}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 3}, {2, 4}, {2, 5}, {3, 4}, {3, 5}, {4, 5}, {1, 2, 3}, {1, 2, 4}, {1, 2, 5}, {1, 3, 4}, {1, 3, 5}, {2, 3, 4}, {2, 4, 5} and {1, 2, 3, 5}.
-
from itertools import combinations
def a(n):
ans = 0
for r in range(n+1):
for s in combinations(range(1,n+1),r):
strss = str(sum(s))
ans += strss==strss[::-1]
return ans
print([a(n) for n in range(21)]) # Michael S. Branicky, Dec 07 2020
-
from functools import lru_cache
from itertools import combinations
@lru_cache(maxsize=None)
def A339507(n):
pallist = set(i for i in range(1,n*(n+1)//2+1) if str(i) == str(i)[::-1])
return 1 if n == 0 else A339507(n-1) + sum(sum(d)+n in pallist for i in range(n) for d in combinations(range(1,n),i)) # Chai Wah Wu, Dec 08 2020
-
from functools import lru_cache
def cond(s): ss = str(s); return ss == ss[::-1]
@lru_cache(maxsize=None)
def b(n, s):
if n == 0: return int(cond(s))
return b(n-1, s) + b(n-1, s+n)
a = lambda n: b(n, 0)
print([a(n) for n in range(100)]) # Michael S. Branicky, Oct 05 2022
A377123
Number of subsets of the first n nonzero triangular numbers whose sum is a nonzero triangular number.
Original entry on oeis.org
1, 2, 4, 5, 8, 13, 18, 29, 48, 81, 136, 228, 420, 747, 1326, 2468, 4520, 8296, 15232, 28196, 52504, 96936, 181699, 340998, 640091, 1207386, 2282956, 4328536, 8211989, 15623003, 29787092, 56831499, 108591159, 207851120, 398222781, 763760138, 1466661416, 2819529654, 5425826011, 10450403468
Offset: 1
a(5) = 8 subsets: {1}, {3}, {6}, {10}, {15}, {6, 15}, {1, 3, 6} and {3, 10, 15}.
-
from math import isqrt
from functools import cache
def cond(s): k = 8*s+1; return s > 0 and isqrt(k)**2 == k
def u(n): return n*(n+1)//2
@cache
def b(n, s):
if n == 0: return int(cond(s))
return b(n-1, s) + b(n-1, s+u(n))
a = lambda n: b(n, 0)
print([a(n) for n in range(1, 51)]) # Michael S. Branicky, Oct 18 2024
Showing 1-4 of 4 results.