A378844 Number of subsets of {1..n} whose arithmetic and harmonic means are both integers.
1, 2, 3, 4, 5, 8, 9, 10, 11, 13, 14, 18, 19, 21, 27, 28, 29, 48, 49, 71, 75, 78, 79, 103, 104, 105, 106, 203, 204, 325, 326, 327, 530, 533, 795, 1198, 1199, 1204
Offset: 1
Examples
a(6) = 8 subsets: {1}, {2}, {3}, {4}, {5}, {6}, {2, 6} and {1, 2, 3, 6}.
Programs
-
Mathematica
a[n_] := Count[Subsets[Range[n]], ?(# != {} && IntegerQ[Mean[#]] && IntegerQ[HarmonicMean[#]] &)]; Array[a, 20] (* _Amiram Eldar, Dec 10 2024 *)
-
PARI
a(n) = {my(c = 0); forsubset(n, s, if(#s && !(vecsum(Vec(s)) % #s) && denominator(#s/sum(i=1,#s,1/s[i])) == 1, c++)); c;} \\ Amiram Eldar, Dec 10 2024
-
Python
from math import lcm from itertools import combinations def A378844(n): m = lcm(*range(2,n+1)) return sum(1 for l in range(1,n+1) for c in combinations(range(1,n+1),l) if not (sum(c)%l or l*m%sum(m//d for d in c))) # Chai Wah Wu, Dec 12 2024
Formula
a(p^k) = a(p^k-1)+1 for p prime (see A339453). - Chai Wah Wu, Dec 12 2024
Extensions
a(25)-a(29) from Amiram Eldar, Dec 10 2024
a(30)-a(33) from Chai Wah Wu, Dec 12 2024
a(34)-a(38) from Chai Wah Wu, Dec 13 2024