Re: FindInstance for sum of primes
- To: mathgroup at smc.vnet.net
- Subject: [mg115539] Re: FindInstance for sum of primes
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Fri, 14 Jan 2011 06:16:42 -0500 (EST)
Here are the first 100 sums of 11 consecutive primes: Clear[f]; f[1] = Total@Prime@Range@11 f[n_] := f[n] = f[n - 1] + Prime[n + 10] - Prime[n - 1] Array[f, {100}] // Timing 160 {0.0009, {160, 195, 233, 271, 311, 353, 399, 443, 491, 539, 583, 631, 677, 725, 779, 833, 883, 931, 979, 1025, 1081, 1139, 1197, 1253, 1313, 1367, 1423, 1483, 1543, 1607, 1673, 1727, 1787, 1843, 1901, 1951, 2011, 2077, 2141, 2203, 2263, 2323, 2383, 2443, 2507, 2573, 2643, 2703, 2757, 2811, 2865, 2925, 2993, 3063, 3125, 3185, 3253, 3321, 3397, 3469, 3541, 3617, 3691, 3757, 3825, 3895, 3967, 4033, 4097, 4159, 4229, 4297, 4369, 4435, 4501, 4565, 4631, 4699, 4763, 4825, 4883, 4943, 5009, 5069, 5135, 5199, 5265, 5337, 5403, 5483, 5567, 5657, 5741, 5823, 5903, 5981, 6065, 6149, 6227, 6305}} Bobby On Thu, 13 Jan 2011 02:27:33 -0600, Peter Pein <petsie at dordos.net> wrote: > 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 > -- DrMajorBob at yahoo.com