Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 1
    $\begingroup$ you are way too humble! calculating your sum for even the first 2000 primes takes less than a second. However, is there a way to get around storing large numbers in sums in memory? It keeps crashing my computer when I try toPrime=5000. $\endgroup$ Commented Mar 26, 2013 at 6:03
  • $\begingroup$ +1 (that's freaking fast!) Can you explain why Accumulate@FoldList[#1 #2 &, 1, Range[n] is so much quicker to Accumulate@Array[#! &, n] + 1? I really don't get it. $\endgroup$ Commented Mar 26, 2013 at 11:23
  • $\begingroup$ @gpap Calculating factorial so many times costs a lot. Since we know we want all the factorials up to Prime[toPrime]-1, we ultimately gain a lot keeping the intermediate results with FoldList. $\endgroup$ Commented Mar 26, 2013 at 12:04
  • $\begingroup$ @MichaelE2 Yes, worked it out myself in the meantime - you multiply the previous result and don't calculate a factorial at every step. Thanks $\endgroup$ Commented Mar 26, 2013 at 12:11
  • 2
    $\begingroup$ Is there any reason why you used #1 #2 & instead of Times? $\endgroup$ Commented Jun 15, 2015 at 12:53