Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: FindInstance for sum of primes

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115586] Re: FindInstance for sum of primes
  • From: leigh pascoe <leigh at evry.inserm.fr>
  • Date: Sat, 15 Jan 2011 04:46:59 -0500 (EST)

Thank you to all who replied to my question. It seems I should have been
more explicit with my question.

I was originally sent the observation that

2011 = 157 + 163 + 167 + 173 + 179 + 181 + 191 + 193 + 197 + 199 + 211
     =Prime[37]+.... Prime[47]

which I took to be of interest because the year (ignoring the 1000's) is
the sum of that same number of consecutive primes. I wondered whether
this was a common phenomenon and tried to answer the question with
Mathematica i.e. if year (mod 1000)=N where N can be expressed as the
sum of N consecutive primes.  So the search was not restricted to 11
consecutive primes but to cases that followed the same rule.

The fastest way to find examples seems to be by inspection with a little
help from Ma.

For the first 1000 primes, generate the lists

list = Total /@ Partition[Prime[Range[1000]], #, 1] & /@ Range[100];
which gives lists of the sums of 1,2,.. 100 primes

then inspect the lists for cases where the sum equals a year (mod 1000)

In[8]:= MemberQ[Mod[list[[#]], 1000], #] & /@ Range[100]

Out[8]= {True, True, True, True, False, True, True, True, True, True, \
True, True, True, True, True, True, True, True, True, True, True, \
True, True, True, True, True, True, True, True, True, True, True, \
True, True, True, True, True, True, False, True, True, False, True, \
True, True, True, True, True, True, True, True, True, True, False, \
False, True, True, True, True, True, True, True, True, True, True, \
True, True, True, True, False, True, True, True, True, True, True, \
True, False, True, True, True, True, False, False, True, True, True, \
False, True, True, True, True, True, True, True, True, True, True, \
True, True}

and we see that such years are quite common.

We can use the function
f[n_, m_] := Sum[Prime[i], {i, n, n + m}];

to find particular examples by trial and error

Some examples would be
{3001, 4001, 7001...} are the sums of 1 (sic) consecutive primes
{1002,4002,10002} are the sums of 2 consecutive primes
etc.
also near in time
5014 is the sum of 14 consecutive primes
6023 is the sum of 23 consecutive primes

No solution was observed for 5 consecutive primes in the range scanned.
However a solution for 5 consecutive primes exists when the number of
primes examined is raised to 10000. I guess that responds to my
curiosity even if it is not a very elegant way of tackling the problem..

In passing I noticed that the year 1212 was the sum of 12 consecutive
primes. Are there any other years of the form NN that are the sum of N
consecutive primes?

Leigh

Le 14/01/2011 12:16, DrMajorBob a =C3=A9crit :
> 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
>>
>


  • Prev by Date: Re: Caution on BibTex references with Mathematica
  • Next by Date: Re: NSolve unable to find all possible roots
  • Previous by thread: Re: FindInstance for sum of primes
  • Next by thread: Cubic equations again...