A022895 Number of solutions to c(1)*prime(1) + ... + c(n)*prime(n) = 1, where c(i) = +-1 for i > 1, c(1) = 1.
0, 0, 0, 1, 0, 1, 0, 3, 0, 8, 0, 22, 0, 70, 0, 218, 0, 708, 0, 2354, 0, 8015, 0, 27561, 0, 95160, 0, 335579, 0, 1202236, 0, 4267477, 0, 15318171, 0, 55248419, 0, 200711050, 0, 733704990, 0, 2696599982, 0, 9941660942, 0, 36928370497, 0, 136801720627, 0
Offset: 1
Keywords
Examples
a(8) counts these 3 solutions: {2, -3, -5, 7, -11, 13, 17, -19}, {2, -3, -5, 7, 11, -13, -17, 19}, {2, -3, 5, -7, -11, 13, -17, 19}.
Links
- Alois P. Heinz, Table of n, a(n) for n = 1..500
Crossrefs
Programs
-
Mathematica
{f, s} = {1, 1}; Table[t = Map[Prime[# + f - 1] &, Range[2, z]]; Count[Map[Apply[Plus, #] &, Map[t # &, Tuples[{-1, 1}, Length[t]]]], s - Prime[f]], {z, 22}] (* A022895, a(n) = number of solutions of "sum = s" using Prime(f) to Prime(f+n-1) *) n = 8; t = Map[Prime[# + f - 1] &, Range[n]]; Map[#[[2]] &, Select[Map[{Apply[Plus, #], #} &, Map[t # &, Map[Prepend[#, 1] &, Tuples[{-1, 1}, Length[t] - 1]]]], #[[1]] == s &]] (* the 3 solutions using n=8 primes; Peter J. C. Moses, Oct 01 2013 *)
-
PARI
A022895(n, rhs=1, firstprime=1)={rhs-=prime(firstprime); my(p=vector(n-1, i, prime(i+firstprime))); sum(i=1, 2^#p-1, sum(j=1, #p, (-1)^bittest(i, j-1)*p[j])==rhs)} \\ For illustrative purpose, too slow for n >> 20. - M. F. Hasler, Aug 08 2015
-
PARI
a(n, s=1-prime(1), p=1)={if(n<=s, if(s==p, n==s, a(abs(n-p), s-p, precprime(p-1))+a(n+p, s-p, precprime(p-1))), if(s<=0, if(n>1,a(abs(s), sum(i=p+1, p+n-1, prime(i)), prime(p+n-1)),!s)))} \\ On function call, s = r.h.s.- smallest prime; during recursion: sum of all primes to be used. - M. F. Hasler, Aug 09 2015
Formula
a(n) = [x^1] Product_{k=2..n} (x^prime(k) + 1/x^prime(k)). - Ilya Gutkovskiy, Jan 26 2024
Extensions
Corrected and extended by Clark Kimberling, Oct 01 2013
a(23)-a(49) from Alois P. Heinz, Aug 06 2015
Cross-references from M. F. Hasler, Aug 08 2015