Re: FindInstance for sum of primes

*To*: mathgroup at smc.vnet.net*Subject*: [mg115517] Re: FindInstance for sum of primes*From*: Peter Pein <petsie at dordos.net>*Date*: Thu, 13 Jan 2011 03:27:33 -0500 (EST)*References*: <igisd3$pr9$1@smc.vnet.net>

On 12.01.2011 01:25, leigh pascoe wrote: > Dear Mathgroup, > > 2011 is the sum of 11 consecutive primes. I want to check if any other > years have a similar property. > > Now define > > f[n_, m_] := Sum[Prime[i], {i, n, n + m}]; > eq = Mod[f[n, m] - year, 1000] == 0 > > and we see that > > In[64]:= Mod[f[37, 10] - 2011, 1000] > > Out[64]= 0 > > but > > In[65]:= FindInstance[eq, {n, m, year}, Integers] > > During evaluation of In[65]:= FindInstance::exvar: The system contains a > nonconstant expression i independent of variables {n,m,year}.>> > > Out[65]= FindInstance[Mod[-year + \!\(\*UnderoverscriptBox[\(\[Sum]\), > \(i = n\), \(m + n\)]\(Prime[i]\)\), 1000] == 0, {n, m, year}, Integers] > > Apparently FindInstance doesn't like the dummy variable "i". How can we > perform this search in Mathematica?? > > LP > Hello Leigh, I can't imagine how to solve your problem using Reduce/FindInstance, but you can construct a table containing sums of k conecutive primes: In[1]:= pSumTable = Mod[ With[{pr = Prime[Range[1000]]}, Table[Total /@ Partition[pr, k, 1], {k, 100}] ], 10000]; say, you want to find 2011. Then use In[2]:= LengthAndStart = Position[pSumTable, 2011, 2] Out[2]= {{1, 305}, {3, 121}, {3, 551}, {9, 494}, {11, 37}, {11, 737}, {29, 170}, {35, 675}, {49, 342}, {49, 395}, {59, 16}, {61, 614}, {83, 241}, {91, 6}, {95, 606}} {11, 37} is the case you mentioned in your post. to verify the results (without the help of pSumTable): In[3]:= Total[Prime[Range[#2, #2 + #1 - 1]]] & @@@ LengthAndStart Out[3]= {2011, 2011, 12011, 32011, 2011, 62011, 32011, 182011, \ 122011, 142011, 12011, 292011, 152011, 22011, 462011} Cheers, Peter