login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A054845 Number of ways of representing n as the sum of one or more consecutive primes. 15
0, 0, 1, 1, 0, 2, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 2, 1, 1, 0, 0, 0, 2, 1, 0, 1, 0, 1, 1, 1, 2, 0, 0, 0, 0, 2, 1, 0, 1, 0, 3, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 2, 0, 0, 1, 0, 1, 2, 2, 1, 0, 0, 0, 0, 0, 2, 1, 0, 0, 2, 2, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 3, 1, 0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 1, 0, 2, 1, 0, 2, 2 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,6
COMMENTS
Moser shows that the average order of a(n) is log 2, that is, Sum_{i=1..n} a(i) ~ n log 2. This shows that a(n) = 0 infinitely often (and with positive density); Moser asks if a(n) = 1 infinitely often, if a(n) = k is solvable for all k, whether these have positive density, and whether the sequence is bounded. - Charles R Greathouse IV, Mar 21 2011
REFERENCES
R. K. Guy, Unsolved Problems In Number Theory, C2.
LINKS
Leo Moser, Notes on number theory. III. On the sum of consecutive primes, Canad. Math. Bull. 6 (1963), pp. 159-161.
Carlos Rivera, Problem 9, The Prime Puzzles and Problems Connection.
FORMULA
G.f.: Sum_{i>=1} Sum_{j>=i} Product_{k=i..j} x^prime(k). - Ilya Gutkovskiy, Apr 18 2019
EXAMPLE
a(5)=2 because of 2+3 and 5. a(17)=2 because of 2+3+5+7 and 17.
41 = 41 = 11+13+17 = 2+3+5+7+11+13, so a(41)=3.
MAPLE
A054845 := proc(n)
local a, mipri, npr, ps ;
a := 0 ;
for mipri from 1 do
for npr from 1 do
ps := add(ithprime(i), i=mipri..mipri+npr-1) ;
if ps = n then
a := a+1 ;
elif ps >n then
break;
end if;
end do:
if ithprime(mipri) > n then
break ;
end if;
end do:
a ;
end proc: # R. J. Mathar, Nov 27 2018
MATHEMATICA
f[n_] := Block[{p = Prime@ Range@ PrimePi@ n}, len = Length@ p; Count[(Flatten[#, 1] &)[Table[ p[[i ;; j]], {i, len}, {j, i, len}]], q_ /; Total@ q == n]]; f[0] = 0; Array[f, 102, 0](* Jean-François Alcover, Feb 16 2011 *) (* fixed by Robert G. Wilson v *)
nn=100; p=Prime[Range[PrimePi[nn]]]; t=Table[0, {nn}]; Do[s=0; j=i; While[s=s+p[[j]]; s<=nn, t[[s]]++; j++], {i, Length[p]}]; Join[{0}, t]
PROG
(PARI){/* program gives values of a(n) for n=0..precprime(nn)-1 */
nn=2000; t=vector(nn+1); forprime(x=2, nn, s=x;
forprime(y=x+1, nn, if(s<=nn, t[s+1]++, break()); s=s+y)); t[1..precprime(nn)]} \\ Zak Seidov, Feb 17 2011, corrected by Michael S. Branicky, Feb 28 2022
(Magma) S:=[0]; for n in [1..104] do count:=0; for q in PrimesUpTo(n) do p:=q; s:=p; while s lt n do p:=NextPrime(p); s+:=p; end while; if s eq n then count+:=1; end if; end for; Append(~S, count); end for; S; // Klaus Brockhaus, Feb 17 2011
(Perl) use ntheory ":all"; my $n=10000; my @W=(0)x($n+1); forprimes { my $s=$_; do { $W[$s]++; $s += ($_=next_prime($_)); } while $s <= $n; } $n; print "$_ $W[$_]\n" for 0..$#W; # Dana Jacobsen, Aug 22 2018
(Python)
from sympy import primerange
def aupton(nn): # modification of PARI by Zak Seidov
alst = [0 for n in range(nn+1)]
for x in primerange(2, nn+1):
s = x
alst[s] += 1
for y in primerange(x+1, nn+1):
s += y
if s <= nn:
alst[s] += 1
else:
break
return alst
print(aupton(101)) # Michael S. Branicky, Feb 17 2022
(Python) # alternate version for going to large n
import heapq
from sympy import prime
from itertools import islice
def agen(): # generator of terms
p = v = prime(1); h = [(p, 1, 1)]; nextcount = 2; oldv = ways = 0
while True:
(v, s, l) = heapq.heappop(h)
if v == oldv: ways += 1
else:
yield ways
for n in range(oldv+1, v): yield 0
ways = 1
if v >= p:
p += prime(nextcount)
heapq.heappush(h, (p, 1, nextcount))
nextcount += 1
oldv = v
v -= prime(s); s += 1; l += 1; v += prime(l)
heapq.heappush(h, (v, s, l))
print(list(islice(agen(), 102))) # Michael S. Branicky, Feb 17 2022
CROSSREFS
Sequence in context: A305490 A113706 A279952 * A317991 A359980 A236853
KEYWORD
nice,nonn
AUTHOR
Jud McCranie, May 25 2000
EXTENSIONS
Edited by N. J. A. Sloane, Oct 27 2008 at the suggestion of Jake M. Foster
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 24 09:18 EDT 2024. Contains 371935 sequences. (Running on oeis4.)