A072820 Largest number of distinct primes to represent n as arithmetic mean.
1, 1, 3, 3, 5, 4, 5, 5, 7, 6, 9, 8, 9, 9, 11, 10, 11, 11, 13, 12, 13, 13, 15, 14, 17, 15, 17, 16, 17, 17, 19, 18, 19, 19, 21, 20, 23, 21, 23, 22, 23, 23, 25, 24, 25, 25, 27, 26, 27, 27, 29, 28, 29, 28, 29, 29, 31, 30, 31, 31, 33, 32, 33, 33, 35, 33, 35, 34, 37, 35, 37, 36, 37, 37
Offset: 2
Keywords
Examples
a(20) = 13: (2+3+5+7+11+13+17+19+23+29+31+41+59)/13 = 20. [corrected by _Jean-François Alcover_, Nov 10 2020]
Links
- Alois P. Heinz, Table of n, a(n) for n = 2..100
- Reinhard Zumkeller, Representing integers as arithmetic means of primes
Crossrefs
Cf. A072701.
Programs
-
Maple
sp:= proc(i) option remember; `if`(i=1, 2, sp(i-1) +ithprime(i)) end: b:= proc(n, i, t) local h; if n<0 then 0 elif n=0 then `if`(t=0, 1, 0) elif i=2 then `if`(n=2 and t=1, 1, 0) else h := b(n, prevprime(i), t); b(n, i, t):= `if`(h>0, h, b(n-i, prevprime(i), t-1)) fi end: a:= proc(n) local i, k; if n<4 then 1 else for k from 2 while sp(k)/k<=n do od: do k:= k-1; if b(k*n, nextprime(k*n -sp(k-1)-1), k)>0 then break fi od; k fi end: seq(a(n), n=2..50); # Alois P. Heinz, Aug 03 2009
-
Mathematica
sp[i_] := sp[i] = If[i == 1, 2, sp[i - 1] + Prime[i]]; b[n_, i_, t_] := b[n, i, t] = Module[{h}, Which[n < 0, 0, n == 0, If[t == 0, 1, 0], i == 2, If[n == 2 && t == 1, 1, 0], True, h = b[n, NextPrime[i, -1], t]; If[h > 0, h, b[n - i, NextPrime[i, -1], t - 1]]]]; a[n_] := a[n] = Module[{k}, If[n < 4, 1, For[k = 2, sp[k]/k <= n, k++]; While[True, k = k - 1; If[b[k n, NextPrime[k n - sp[k - 1] - 1], k] > 0, Break[]]]; k]]; Table[Print[n, " ", a[n]]; a[n], {n, 2, 100}] (* Jean-François Alcover, Nov 13 2020, after Alois P. Heinz *)
Extensions
More terms from Alois P. Heinz, Aug 03 2009