Summation of primes: Difference between revisions

J draft
(J draft)
Line 351:
<pre>142913828922</pre>
 
 
=={{header|J}}==
<syntaxhighlight lang=J>+/p: i. p:inv 2e6
142913828922</syntaxhighlight>
 
Here, p: represents what might be thought of as an array of primes, and its argument represents array indices of those primes. Similarly, the result p:inv represents the smallest index whose prime is no less than its argument.
 
So...
<syntaxhighlight lang=J> p:inv 2e6
148933
p: p:inv 2e6
2000003</syntaxhighlight>
 
Also, <code>i. n</code> returns a list of indices starting at zero and ending at one less than n (assuming n is a positive integer which of course it is, here).
 
And, (for people not familiar with J): <code>+/</code> sums a list (evaluates the hypothetical expression which would result from insert <code>+</code> between each element of that list).
 
=={{header|jq}}==
6,951

edits