Re: How to count
- To: mathgroup at smc.vnet.net
- Subject: [mg125730] Re: How to count
- From: danl at wolfram.com
- Date: Fri, 30 Mar 2012 04:35:39 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jl14ig$l5e$1@smc.vnet.net>
On Thursday, March 29, 2012 2:56:00 AM UTC-5, Artur wrote: > Dear Mathematica Gurus! > > I have seriously problem with counting distances between smallest square > bigger than n! (for big n) e.g. > > aa = {}; Do[k = 1 + Floor[Sqrt[n!]]; kk = k^2 - n!; Print[kk]; > kkk = N[Log[kk], 100]; Print[kkk]; > AppendTo[aa, kkk], {n, 1, 10000000, 1000000}]; aa > > Who have idea how to count this on Mathematica? > > Best wishes > Artur It is likely to be slow no matter what you do. Here are a couple of approaches though I've not attempted to verify results and so I cannot be sure precision is sufficiently high. I show with numbers a factor of 10 smaller than yours, so expect your examples to be correspondingly slower. bottom = 100000; Timing[bb = Table[Ceiling[Exp[LogGamma[N[n+1,n]]/2]], {n,bottom,10*bottom,bottom}];] Out[16]= {671.196962, Null} Around 30% faster: sqrtFactorial[n_] := Module[ {start, x}, start = Ceiling[Exp[LogGamma[N[n+1]]/2]]; Ceiling[Exp[x] /. FindRoot[x==LogGamma[n+1]/2, {x,start}, WorkingPrecision->3*n, AccuracyGoal->n, PrecisionGoal->n]] ] Timing[dd = Table[sqrtFactorial[n], {n,bottom,10*bottom,bottom}];] Out[26]= {463.363558, Null} In[27]:= dd===bb Out[27]= True I will check that at least the last one is correct. In[28]:= dd[[-1]]^2 > (10*bottom)! Out[28]= True In[29]:= (dd[[-1]]-1)^2 < (10*bottom)! Out[29]= True Daniel Lichtblau Wolfram Research