RE: Re: Writing a program to hunt for a prime between n^2 and (n+1)^2

*To*: mathgroup at smc.vnet.net*Subject*: [mg39199] RE: [mg39174] Re: Writing a program to hunt for a prime between n^2 and (n+1)^2*From*: "Diana Mecum" <diana53 at earthlink.net>*Date*: Mon, 3 Feb 2003 01:10:12 -0500 (EST)*Reply-to*: <diana53 at earthlink.net>*Sender*: owner-wri-mathgroup at wolfram.com

Thanks Andrzej, this works great. Diana -----Original Message----- From: Andrzej Kozlowski [mailto:akoz at mimuw.edu.pl] To: mathgroup at smc.vnet.net Subject: [mg39199] Re: [mg39174] Re: Writing a program to hunt for a prime between n^2 and (n+1)^2 One way that is at least simpler and faster then yours is just to use the NextPrime function in the << NumberTheory`NumberTheoryFunctions` In[1]:= <<NumberTheory`NumberTheoryFunctions` In[2]:= funct1[n_]:=NextPrime[n^2] In[3]:= funct1[234] Out[3]= 54767 (Actually NextPrime is very easy to define yourself so you do not even need to use the package, e.g: nextprime[n_]:=If[PrimeQ[n],n,nextprime[n+1]]) Here is a little more interesting way to get the same answer: funct2[n_] := Prime[PrimePi[n^2] + 1] funct2[234] 54767 This is maybe more "snazzy" but unfortunately it only works for relatively small n. On Sunday, February 2, 2003, at 03:13 PM, Diana wrote: > My program, which is not fancy: > > NRange = Flatten[{n, Range[10, 20, 1]}] > > NSquared = Flatten[NRange^2] > > NPlus1Squared = Flatten[(NRange+1)^2] > > FirstPrimeGreaterNSquared=Flatten[{"Prime>n^2",Table[NestWhile[#1+1&,n^ > 2,!(P > rimeQ[#1])&],{n,10,20}]}] > > {NRange, NSquared, FirstPrimeGreaterNSquared, NPlus1Squared} // > TableForm > > Are there ideas to make this more snazzy, and accomplish the same > thing? > > Thanks, > > Diana > > "Diana" <diana53xiii at earthlink.remove13.net> wrote in message news:... >> Folks, >> >> I am trying to come up with a snazzy way to hunt for a prime between >> n^2 > and >> (n+1)^2. >> >> Some ideas? >> >> Thanks, Diana >> -- >> ===================================================== >> "God made the integers, all else is the work of man." >> L. Kronecker, Jahresber. DMV 2, S. 19. >> >> > > > > Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/