Mathematica 9 is now available
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: [mg115524] Re: FindInstance for sum of primes
  • From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
  • Date: Thu, 13 Jan 2011 03:28:55 -0500 (EST)
  • References: <igisd3$pr9$1@smc.vnet.net>

I'd go for brute force. It is fast enough. The following takes less
tha 0.1 s on my laptop

In[309]:=
Flatten[Cases[
     MapIndexed[{Total[#1], #2[[1]]} &,
      Partition[Prime[Range[1, 306]], #, 1]], {x_, y_} /;
       2000 <= x <= 2020 -> {x, Prime[Range[y, y + # - 1]]}] & /@
   Range[33], {2}]

Out[309]=  {{{2003, {2003}}, {2006, {997, 1009}}, {2011, {661,
     673, 677}}, {2002, {491, 499, 503, 509}}, {2015, {389, 397, 401,
     409, 419}}, {2011, {157, 163, 167, 173, 179, 181, 191, 193, 197,
     199, 211}}, {2002, {107, 109, 113, 127, 131, 137, 139, 149, 151,
     157, 163, 167, 173, 179}}, {2016, {71, 73, 79, 83, 89, 97, 101,
     103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
     157}}}, {{2011, {2011}}}, {{2017, {2017}}}}

I assume you're interested in nearby years. I've taken 2000 <= x <=
2020. For this case, you can check that this implies a maximum number
of primes involved of 33 (longer rows always sum to larger values than
2020). It also doesn't make sense to consider more than the first 306
primes as the 307th is larger than 2020. If you want a different range
you should adjust these two values.

Cheers -- Sjoerd

On Jan 12, 1:25 am, leigh pascoe <le... at evry.inserm.fr> 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}, Inte=
gers]
>
> Apparently FindInstance doesn't like the dummy variable "i". How can we
> perform this search in Mathematica??
>
> LP



  • Prev by Date: Re: Having some trouble with plot and solve
  • Next by Date: Re: question on diophantine equations in Mathematica
  • Previous by thread: Re: FindInstance for sum of primes
  • Next by thread: Re: FindInstance for sum of primes