Extreme primes: Difference between revisions

Added Easylang
(Added Easylang)
 
(26 intermediate revisions by 11 users not shown)
Line 1:
{{draft task}}
<big>Definition</big>
;Definition
<br><br>
Write down the first prime number, add the next prime number and if it is prime, add it to the series and so on. These primes are called '''extreme primes'''.
<br><br>
<big>;Task</big>
Find and display the first '''30 extreme primes''' on this page.
<br><br>
<br>
Find and display the first '''30 p extreme prime''' number on this page.
;Stretch
Find and display the '''1,000th''', '''2,000th''', '''3,000th''', '''4,000th''' and '''5,000th''' extreme primes and for each one show the prime number '''p''' up to and including which primes need to be summed to obtain it.
<br>
;Related (and near duplicate) tasks
* [[Prime numbers p for which the sum of primes less than or equal to p is prime]]
* [[Summarize primes]]
;Reference
[[oeis:A013918|OEIS sequence A013918]]
<br><br>
 
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<syntaxhighlight lang="algol68">
BEGIN # sum the primes below n and report the sums that are prime #
PR read "primes.incl.a68" PR # include prime utilities #
[]BOOL prime = PRIMESIEVE 2 000 000; # sieve the primes to 2 000 000 #
# returns TRUE if n is prime, FALSE otherwise #
PROC is prime = ( LONG INT n )BOOL:
IF n <= UPB prime THEN prime[ SHORTEN n ]
ELIF NOT ODD n THEN FALSE
ELSE
LONG INT f := 3;
LONG INT f2 := 9;
LONG INT to next := 16;
BOOL is a prime := TRUE;
WHILE f2 <= n AND is a prime DO
is a prime := n MOD f /= 0;
f +:= 2;
f2 +:= to next;
to next +:= 8
OD;
is a prime
FI # is prime # ;
# sum the primes and test the sums #
print( ( "The first 30 extreme primes:", newline ) );
print( ( whole( 2, -6 ), " " ) ); # 2 is the first prime so is "extreme" #
INT prime sum count := 1;
LONG INT prime sum := 2;
LONG INT candidate := 1;
WHILE prime sum count < 5 000 DO
IF is prime( candidate +:= 2 ) THEN
prime sum +:= candidate; # have another prime #
IF is prime( prime sum ) THEN # the prime sum is also prime #
prime sum count +:= 1;
IF prime sum count <= 30 THEN
print( ( whole( prime sum, -6 )
, IF prime sum count MOD 10 = 0 THEN newline ELSE " " FI
)
)
ELIF prime sum count MOD 1000 = 0 THEN
print( ( "Extreme prime ", whole( prime sum count, -5 )
, " is ", whole( candidate, -12 )
, ", sum: ", whole( prime sum, -18 )
, newline
)
)
FI
FI
FI
OD
END
</syntaxhighlight>
{{out}}
<pre>
The first 30 extreme primes:
2 5 17 41 197 281 7699 8893 22039 24133
25237 28697 32353 37561 38921 43201 44683 55837 61027 66463
70241 86453 102001 109147 116533 119069 121631 129419 132059 263171
Extreme prime 1000 is 196831, sum: 1657620079
Extreme prime 2000 is 495571, sum: 9744982591
Extreme prime 3000 is 808837, sum: 24984473177
Extreme prime 4000 is 1152763, sum: 49394034691
Extreme prime 5000 is 1500973, sum: 82195983953
</pre>
 
=={{header|C}}==
{{trans|Wren}}
{{libheader|GMP}}
<syntaxhighlight lang="c">#include <stdio.h>
#include <locale.h>
#include <gmp.h>
 
int main() {
int i, m, extremes[30], count = 1;
mpz_t sum, p;
unsigned long usum, up;
extremes[0] = 2;
mpz_init_set_ui(sum, 2);
mpz_init_set_ui(p, 3);
setlocale(LC_NUMERIC, "");
while (1) {
mpz_add(sum, sum, p);
if (mpz_probab_prime_p(sum, 5) > 0) {
++count;
if (count <= 30) {
extremes[count-1] = (int)mpz_get_ui(sum);
}
if (count == 30) {
printf("The first 30 extreme primes are:\n");
for (i = 0; i < 30; ++i) {
printf("%'7d ", extremes[i]);
if (!((i+1)%6)) printf("\n");
}
printf("\n");
} else if (!(count % 1000)) {
m = count / 1000;
if (m < 6 || m == 30 || m == 40 || m == 50) {
usum = mpz_get_ui(sum);
up = mpz_get_ui(p);
printf("The %'6dth extreme prime is: %'18ld for p <= %'10ld\n", count, usum, up);
if (m == 50) break;
}
}
}
mpz_nextprime(p, p);
}
mpz_clear(sum);
mpz_clear(p);
return 0;
}</syntaxhighlight>
 
{{out}}
<pre>
Identical to Wren output.
</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
prim = 2
proc nextprim . .
repeat
prim += 1
until isprim prim = 1
.
.
while cnt < 30
n += prim
if isprim n = 1
cnt += 1
write n & " "
.
nextprim
.
</syntaxhighlight>
{{out}}
<pre>
2 5 17 41 197 281 7699 8893 22039 24133 25237 28697 32353 37561 38921 43201 44683 55837 61027 66463 70241 86453 102001 109147 116533 119069 121631 129419 132059 263171
</pre>
 
=={{header|FreeBASIC}}==
Line 36 ⟶ 193:
{{out}}
<pre>Similar to Ring entry.</pre>
 
=={{header|Go}}==
{{trans|Wren}}
{{libheader|GMP(Go wrapper)}}
{{libheader|Go-rcu}}
Based on Wren's GMP version but about 4 times slower as our GMP wrapper doesn't expose the ''Mpz_nextprime'' function. We're therefore using our own very simple version instead which is much slower.
<syntaxhighlight lang="go">package main
 
import (
"fmt"
big "github.com/ncw/gmp"
"rcu"
)
 
func nextPrime(n *big.Int) *big.Int {
m := new(big.Int).Set(n)
z := new(big.Int)
zero := new(big.Int)
one := big.NewInt(1)
two := big.NewInt(2)
if z.Rem(m, two).Cmp(zero) == 0 {
m.Add(m, one)
} else {
m.Add(m, two)
}
for {
if m.ProbablyPrime(0) {
return m
}
m.Add(m, two)
}
}
 
func main() {
extremes := []int{2}
sum := big.NewInt(2)
count := 1
p := big.NewInt(3)
for {
sum.Add(sum, p)
if sum.ProbablyPrime(0) {
count++
if count <= 30 {
extremes = append(extremes, int(sum.Uint64()))
}
if count == 30 {
fmt.Println("The first 30 extreme primes are:")
rcu.PrintTable(extremes, 6, 7, true)
fmt.Println()
} else if count%1000 == 0 {
m := count / 1000
if m < 6 || m == 30 || m == 40 || m == 50 {
scount := rcu.Commatize(count)
ssum := rcu.Commatize(sum.Uint64())
sp := rcu.Commatize(p.Uint64())
fmt.Printf("The %6sth extreme prime is: %18s for p <= %10s\n", scount, ssum, sp)
if m == 50 {
return
}
}
}
}
p.Set(nextPrime(p))
}
}</syntaxhighlight>
 
{{out}}
<pre>
Identical to Wren output.
</pre>
 
=={{header|J}}==
Line 46 ⟶ 273:
 
This would be more efficient if we had used 3e3 (216 extreme primes) rather than 4e4 (1942 extreme primes)
 
=={{header|jq}}==
'''Adapted from [[#Wren|Wren]]'''
 
'''Works with both jq and gojq, the C and Go implementations of jq''' ...
 
Using the generic utilities given immediately below, one solution to the problem
of generating the first 30 extreme primes could be written as follows:
 
<syntaxhighlight lang=jq>
def primes:
2 | recurse(nextprime);
def extremes:
foreach primes as $p (0; . + $p)
| select(is_prime);
 
limit(30; extremes)
</syntaxhighlight>
A program that solves both the primary and stretch tasks is given below.
 
'''Generic Utilities'''
<syntaxhighlight lang=jq>
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
def nwise($n):
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end;
n;
 
def is_prime:
. as $n
| if ($n < 2) then false
elif ($n % 2 == 0) then $n == 2
elif ($n % 3 == 0) then $n == 3
elif ($n % 5 == 0) then $n == 5
elif ($n % 7 == 0) then $n == 7
elif ($n % 11 == 0) then $n == 11
elif ($n % 13 == 0) then $n == 13
elif ($n % 17 == 0) then $n == 17
elif ($n % 19 == 0) then $n == 19
else
($n | sqrt) as $rt
| 23
| until( . > $rt or ($n % . == 0); .+2)
| . > $rt
end;
 
def nextprime:
(if .%2==0 then 1 else 2 end) as $n
| first(range(.+$n; infinite;2) | select(is_prime));
</syntaxhighlight>
'''The Tasks'''
<syntaxhighlight lang=jq>
{ extremes:[2],
sum:2,
p:3,
count:1 }
| while (.count <= 5000;
.emit = null
| .sum += .p
| if .sum|is_prime
then .count += 1
| if .count <= 30
then .extremes += [.sum]
| if .count == 30
then .emit = "The first 30 extreme primes are:\n"
| .emit += ([.extremes | nwise(10) | map(lpad(7)) | join(" ") ] | join("\n"))
| .emit += "\n"
else .
end
elif .count % 1000 == 0
then .emit = "The \(.count)th extreme prime is: \(.sum) for p <= \(.p)"
else .
end
else .
end
| .p |= nextprime
)
| .emit // empty
</syntaxhighlight>
{{output}}
<pre>
The first 30 extreme primes are:
2 5 17 41 197 281 7699 8893 22039 24133
25237 28697 32353 37561 38921 43201 44683 55837 61027 66463
70241 86453 102001 109147 116533 119069 121631 129419 132059 263171
 
The 1000th extreme prime is: 1657620079 for p <= 196831
The 2000th extreme prime is: 9744982591 for p <= 495571
The 3000th extreme prime is: 24984473177 for p <= 808837
The 4000th extreme prime is: 49394034691 for p <= 1152763
The 5000th extreme prime is: 82195983953 for p <= 1500973
</pre>
 
=={{header|Julia}}==
Line 85 ⟶ 405:
263171
</syntaxhighlight>
=== Stretch task ===
{{trans|Python}}
<syntaxhighlight lang="julia">using Primes
 
let
 
ecount, p, n = 0, 0, 0
 
while ecount < 50_000
p = nextprime(p + 1)
n += p
if isprime(n)
ecount += 1
if ecount < 31
println("Sum of prime series up to $p: prime $n")
elseif ecount in [1000, 2000, 3000, 4000, 5000, 30_000, 40_000, 50_000]
println("Sum of $ecount in prime series up to $p: prime $n")
end
end
end
 
end
</syntaxhighlight>{{out}}
<pre>
Sum of prime series up to 2: prime 2
Sum of prime series up to 3: prime 5
Sum of prime series up to 7: prime 17
Sum of prime series up to 13: prime 41
Sum of prime series up to 37: prime 197
Sum of prime series up to 43: prime 281
Sum of prime series up to 281: prime 7699
Sum of prime series up to 311: prime 8893
Sum of prime series up to 503: prime 22039
Sum of prime series up to 541: prime 24133
Sum of prime series up to 557: prime 25237
Sum of prime series up to 593: prime 28697
Sum of prime series up to 619: prime 32353
Sum of prime series up to 673: prime 37561
Sum of prime series up to 683: prime 38921
Sum of prime series up to 733: prime 43201
Sum of prime series up to 743: prime 44683
Sum of prime series up to 839: prime 55837
Sum of prime series up to 881: prime 61027
Sum of prime series up to 929: prime 66463
Sum of prime series up to 953: prime 70241
Sum of prime series up to 1061: prime 86453
Sum of prime series up to 1163: prime 102001
Sum of prime series up to 1213: prime 109147
Sum of prime series up to 1249: prime 116533
Sum of prime series up to 1277: prime 119069
Sum of prime series up to 1283: prime 121631
Sum of prime series up to 1307: prime 129419
Sum of prime series up to 1321: prime 132059
Sum of prime series up to 1949: prime 263171
Sum of 1000 in prime series up to 196831: prime 1657620079
Sum of 2000 in prime series up to 495571: prime 9744982591
Sum of 3000 in prime series up to 808837: prime 24984473177
Sum of 4000 in prime series up to 1152763: prime 49394034691
Sum of 5000 in prime series up to 1500973: prime 82195983953
Sum of 30000 in prime series up to 12437401: prime 4889328757567
Sum of 40000 in prime series up to 17245391: prime 9207632380589
Sum of 50000 in prime series up to 22272277: prime 15118097491121
</pre>
 
=={{header|Nim}}==
{{incorrect|Nim|outputting the next prime which was not added to ep (yet)}}
{{libheader|Nim-Integers}}
We use third party package “integers” to get Miller-Rabin primality test.
<syntaxhighlight lang="Nim">import std/[strformat, strutils]
import integers
 
echo "First 30 extreme primes:"
var ep = newInteger(0)
var count = 0
var lim = 1000
var p = newInteger(2)
while true:
ep += p
p = p.nextPrime
if ep.isPrime:
inc count
if count <= 30:
stdout.write &"{ep:>6}"
stdout.write if count mod 6 == 0: '\n' else: ' '
if count == 30: echo()
elif count == lim:
echo &"Sum of {count} in prime series up to {insertSep($p):>9}: prime {insertSep($ep):>14}"
inc lim, 1000
if lim > 5000: break
</syntaxhighlight>
 
{{out}}
<pre>First 30 extreme primes:
2 5 17 41 197 281
7699 8893 22039 24133 25237 28697
32353 37561 38921 43201 44683 55837
61027 66463 70241 86453 102001 109147
116533 119069 121631 129419 132059 263171
 
Sum of 1000 in prime series up to 196_837: prime 1_657_620_079
Sum of 2000 in prime series up to 495_587: prime 9_744_982_591
Sum of 3000 in prime series up to 808_853: prime 24_984_473_177
Sum of 4000 in prime series up to 1_152_773: prime 49_394_034_691
Sum of 5000 in prime series up to 1_500_991: prime 82_195_983_953
</pre>
 
=={{header|Phix}}==
Line 91 ⟶ 516:
<span style="color: #008080;">constant</span> <span style="color: #000000;">lim</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">30</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">extremes</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">ep</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">np</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">10</span>
<span style="color: #008080;">while</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">extremes</span><span style="color: #0000FF;">)<</span><span style="color: #000000;">lim</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">epnp</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8000000;">get_prime1</span><span style="color: #0000FF;">(;</span> <span style="color: #000000;">npep</span> <span style="color: #0000FF;">);+=</span> <span style="color: #0000007060A8;">npget_prime</span> <span style="color: #0000FF;">+=(</span> <span style="color: #000000;">1np</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ep</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #000000;">extremes</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">ep</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first %d extreme primes are:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">lim</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">extremes</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">:=</span><span style="color: #008000;">"%,7d"</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #004080;">mpz</span> <span style="color: #000000;">z</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mpz_init</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ep</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">found</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">30</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">p</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">tgt</span> <span style="color: #008080;">in</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1e3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2e3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3e3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4e3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5e3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3e4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4e4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5e4</span><span style="color: #0000FF;">}</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">found</span><span style="color: #0000FF;"><</span><span style="color: #000000;">tgt</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">np</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">;</span> <span style="color: #000000;">p</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">get_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">np</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">mpz_add_ui</span><span style="color: #0000FF;">(</span><span style="color: #000000;">z</span><span style="color: #0000FF;">,</span><span style="color: #000000;">z</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">get_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">np</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">p</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">mpz_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">z</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #000000;">found</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">zs</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mpz_get_str</span><span style="color: #0000FF;">(</span><span style="color: #000000;">z</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The %,dth extreme prime is %s (primes[1..%,d]&lt;=%,d)\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">tgt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">zs</span><span style="color: #0000FF;">,</span><span style="color: #000000;">np</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</syntaxhighlight>-->
{{out}}
Line 106 ⟶ 543:
61,027 66,463 70,241 86,453 102,001 109,147
116,533 119,069 121,631 129,419 132,059 263,171
 
The 1,000th extreme prime is 1,657,620,079 (primes[1..17,722]<=196,831)
The 2,000th extreme prime is 9,744,982,591 (primes[1..41,198]<=495,571)
The 3,000th extreme prime is 24,984,473,177 (primes[1..64,596]<=808,837)
The 4,000th extreme prime is 49,394,034,691 (primes[1..89,504]<=1,152,763)
The 5,000th extreme prime is 82,195,983,953 (primes[1..114,236]<=1,500,973)
The 30,000th extreme prime is 4,889,328,757,567 (primes[1..814,900]<=12,437,401)
The 40,000th extreme prime is 9,207,632,380,589 (primes[1..1,106,004]<=17,245,391)
The 50,000th extreme prime is 15,118,097,491,121 (primes[1..1,405,244]<=22,272,277)
</pre>
 
=={{header|Python}}==
<syntaxhighlight lang="python">""" rosettacode.org/wiki/Extreme_primes """
 
from sympy import isprime, nextprime
 
ecount, p, n = 0, 0, 0
 
while ecount < 50_000:
p = nextprime(p)
n += p
if isprime(n):
ecount += 1
if ecount < 31:
print(f'Sum of prime series up to {p}: prime {n}')
if ecount in [1000, 2000, 3000, 4000, 5000, 30_000, 40_000, 50_000]:
print(
f'Sum of {ecount :,} in prime series up to {p :,}: prime {n :,}')
</syntaxhighlight>{{out}}
<pre>
Sum of prime series up to 2: prime 2
Sum of prime series up to 3: prime 5
Sum of prime series up to 7: prime 17
Sum of prime series up to 13: prime 41
Sum of prime series up to 37: prime 197
Sum of prime series up to 43: prime 281
Sum of prime series up to 281: prime 7699
Sum of prime series up to 311: prime 8893
Sum of prime series up to 503: prime 22039
Sum of prime series up to 541: prime 24133
Sum of prime series up to 557: prime 25237
Sum of prime series up to 593: prime 28697
Sum of prime series up to 619: prime 32353
Sum of prime series up to 673: prime 37561
Sum of prime series up to 683: prime 38921
Sum of prime series up to 733: prime 43201
Sum of prime series up to 743: prime 44683
Sum of prime series up to 839: prime 55837
Sum of prime series up to 881: prime 61027
Sum of prime series up to 929: prime 66463
Sum of prime series up to 953: prime 70241
Sum of prime series up to 1061: prime 86453
Sum of prime series up to 1163: prime 102001
Sum of prime series up to 1213: prime 109147
Sum of prime series up to 1249: prime 116533
Sum of prime series up to 1277: prime 119069
Sum of prime series up to 1283: prime 121631
Sum of prime series up to 1307: prime 129419
Sum of prime series up to 1321: prime 132059
Sum of prime series up to 1949: prime 263171
Sum of 1,000 in prime series up to 196,831: prime 1,657,620,079
Sum of 2,000 in prime series up to 495,571: prime 9,744,982,591
Sum of 3,000 in prime series up to 808,837: prime 24,984,473,177
Sum of 4,000 in prime series up to 1,152,763: prime 49,394,034,691
Sum of 5,000 in prime series up to 1,500,973: prime 82,195,983,953
Sum of 30,000 in prime series up to 12,437,401: prime 4,889,328,757,567
Sum of 40,000 in prime series up to 17,245,391: prime 9,207,632,380,589
Sum of 50,000 in prime series up to 22,272,277: prime 15,118,097,491,121
</pre>
 
=={{header|Raku}}==
So we're just gonna keep doing the same task over and over with slightly different names?
 
Primes equal to the sum of the first k primes for some k.
<syntaxhighlight lang="raku" line>use Lingua::EN::Numbers;
 
say $_».&comma».fmt("%7s").batch(10).join: "\n" for
(([\+] (^∞).grep: &is-prime).grep: &is-prime)[^30,999,1999,2999,3999,4999];</syntaxhighlight>
{{out}}
<pre> 2 5 17 41 197 281 7,699 8,893 22,039 24,133
25,237 28,697 32,353 37,561 38,921 43,201 44,683 55,837 61,027 66,463
70,241 86,453 102,001 109,147 116,533 119,069 121,631 129,419 132,059 263,171
1,657,620,079
9,744,982,591
24,984,473,177
49,394,034,691
82,195,983,953</pre>
 
=={{header|Ring}}==
Line 150 ⟶ 673:
done...
</pre>
 
=={{header|RPL}}==
{{works with|HP|49}}
« 0 → max sum
« { } 1
'''DO'''
NEXTPRIME
DUP 'sum' STO+
'''IF''' sum ISPRIME? '''THEN''' SWAP sum + SWAP '''END'''
'''UNTIL''' OVER SIZE max ≥ '''END'''
DROP2
» » ‘<span style="color:blue">XPRIM</span>’ STO
30 <span style="color:blue">XPRIM</span>
{{out}}
<pre>
1: { 2 5 17 41 197 281 7699 8893 22039 24133 25237 28697 32353 37561 38921 43201 44683 55837 61027 66463 70241 86453 102001 109147 116533 119069 121631 129419 132059 263171 }
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require 'prime'
 
sum, n = 0, 30
extreme_primes = Prime.lazy.filter_map{|pr|sum += pr; [pr, sum] if sum.prime?}
 
puts "The first #{n} extreme primes are:"
extreme_primes.first(30).map(&:last).each_slice(10){|slice| puts "%8d"*slice.size % slice}
 
sum = 0
puts
extreme_primes.first(5000).each_slice(1000).with_index(1) do|slice, i|
puts "The %dth extreme prime is sum of primes upto %10d: %12d" % [i*1000, *slice.last]
end
</syntaxhighlight>
{{out}}
<pre>The first 30 extreme primes are:
2 5 17 41 197 281 7699 8893 22039 24133
25237 28697 32353 37561 38921 43201 44683 55837 61027 66463
70241 86453 102001 109147 116533 119069 121631 129419 132059 263171
 
The 1000th extreme prime is sum of primes upto 196831: 1657620079
The 2000th extreme prime is sum of primes upto 495571: 9744982591
The 3000th extreme prime is sum of primes upto 808837: 24984473177
The 4000th extreme prime is sum of primes upto 1152763: 49394034691
The 5000th extreme prime is sum of primes upto 1500973: 82195983953
</pre>
=={{header|Sidef}}==
{{trans|Julia}}
<syntaxhighlight lang="ruby">var(c,p,n) = (0,0,0)
 
while (c < 50_000) {
p.next_prime!
n += p
if (n.is_prime) {
++c
if (c <= 30) {
say "Sum of prime series up to #{p}: prime #{n}"
}
elsif (c ~~ [1000, 2000, 3000, 4000, 5000, 30_000, 40_000, 50_000]) {
say ("Sum of #{c.commify} in prime series up to #{p}: prime #{n}")
}
}
}</syntaxhighlight>
{{out}}
<pre>Sum of prime series up to 2: prime 2
Sum of prime series up to 3: prime 5
Sum of prime series up to 7: prime 17
Sum of prime series up to 13: prime 41
Sum of prime series up to 37: prime 197
Sum of prime series up to 43: prime 281
Sum of prime series up to 281: prime 7699
Sum of prime series up to 311: prime 8893
Sum of prime series up to 503: prime 22039
Sum of prime series up to 541: prime 24133
Sum of prime series up to 557: prime 25237
Sum of prime series up to 593: prime 28697
Sum of prime series up to 619: prime 32353
Sum of prime series up to 673: prime 37561
Sum of prime series up to 683: prime 38921
Sum of prime series up to 733: prime 43201
Sum of prime series up to 743: prime 44683
Sum of prime series up to 839: prime 55837
Sum of prime series up to 881: prime 61027
Sum of prime series up to 929: prime 66463
Sum of prime series up to 953: prime 70241
Sum of prime series up to 1061: prime 86453
Sum of prime series up to 1163: prime 102001
Sum of prime series up to 1213: prime 109147
Sum of prime series up to 1249: prime 116533
Sum of prime series up to 1277: prime 119069
Sum of prime series up to 1283: prime 121631
Sum of prime series up to 1307: prime 129419
Sum of prime series up to 1321: prime 132059
Sum of prime series up to 1949: prime 263171
Sum of 1,000 in prime series up to 196831: prime 1657620079
Sum of 2,000 in prime series up to 495571: prime 9744982591
Sum of 3,000 in prime series up to 808837: prime 24984473177
Sum of 4,000 in prime series up to 1152763: prime 49394034691
Sum of 5,000 in prime series up to 1500973: prime 82195983953
Sum of 30,000 in prime series up to 12437401: prime 4889328757567
Sum of 40,000 in prime series up to 17245391: prime 9207632380589
Sum of 50,000 in prime series up to 22272277: prime 15118097491121</pre>
 
=={{header|Wren}}==
===Wren-CLI===
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="wren">import "./math" for Int
This is very similar to the [[Prime numbers p for which the sum of primes less than or equal to p is prime]] task which itself was a near duplicate of the [[Summarize primes]] task so I'm highly dubious about converting it to a separate draft task. I also found it at [[oeis:A013918|OEIS-A013918]] though it doesn't appear to have a recognized name.
--- Based on the above reasons, please delete this task. Thanks in advance. --- CalmoSoft
<syntaxhighlight lang="ecmascript">import "./math" for Int
import "./fmt" for Fmt
 
var primes = Int.primeSieve(2000) // say
var extremes = [2]
var sum = 2
var p = 3
for (p in primes.skip(1)) {
var count = 1
while (true) {
sum = sum + p
if (Int.isPrime(sum)) {
extremes.add(sum)count = count + 1
if (extremes.count =<= 30) break{
extremes.add(sum)
}
if (count == 30) {
System.print("The first 30 extreme primes are:")
Fmt.tprint("$,7d ", extremes, 6)
System.print()
} else if (count % 1000 == 0) {
Fmt.print("The $,r extreme prime is: $,14d for p <= $,9d", count, sum, p)
if (count == 5000) return
}
}
p = Int.nextPrime(p)
}
}</syntaxhighlight>
System.print("The first 30 extreme primes are:")
Fmt.tprint("$,7d ", extremes, 6)</syntaxhighlight>
 
{{out}}
<pre>
The first 30 extreme primes are:
2 5 17 41 197 281
7,699 8,893 22,039 24,133 25,237 28,697
32,353 37,561 38,921 43,201 44,683 55,837
61,027 66,463 70,241 86,453 102,001 109,147
116,533 119,069 121,631 129,419 132,059 263,171
 
The 1,000th extreme prime is: 1,657,620,079 for p <= 196,831
The 2,000th extreme prime is: 9,744,982,591 for p <= 495,571
The 3,000th extreme prime is: 24,984,473,177 for p <= 808,837
The 4,000th extreme prime is: 49,394,034,691 for p <= 1,152,763
The 5,000th extreme prime is: 82,195,983,953 for p <= 1,500,973
</pre>
 
===Embedded (GMP)===
{{libheader|Wren-gmp}}
<syntaxhighlight lang="wren">import "./gmp" for Mpz
import "./fmt" for Fmt
 
var extremes = [2]
var sum = Mpz.two
var count = 1
var p = Mpz.three
while (true) {
sum.add(p)
if (sum.probPrime(5) > 0) {
count = count + 1
if (count <= 30) {
extremes.add(sum.toNum)
}
if (count == 30) {
System.print("The first 30 extreme primes are:")
Fmt.tprint("$,7i ", extremes, 6)
System.print()
} else if (count % 1000 == 0) {
var m = count / 1000
if (m < 6 || m == 30 || m == 40 || m == 50) {
Fmt.print("The $,8r extreme prime is: $,18i for p <= $,10i", count, sum, p)
if (m == 50) return
}
}
}
p.nextPrime
}</syntaxhighlight>
 
{{out}}
<pre>
The first 30 extreme primes are:
2 5 17 41 197 281
7,699 8,893 22,039 24,133 25,237 28,697
32,353 37,561 38,921 43,201 44,683 55,837
61,027 66,463 70,241 86,453 102,001 109,147
116,533 119,069 121,631 129,419 132,059 263,171
 
The 1,000th extreme prime is: 1,657,620,079 for p <= 196,831
The 2,000th extreme prime is: 9,744,982,591 for p <= 495,571
The 3,000th extreme prime is: 24,984,473,177 for p <= 808,837
The 4,000th extreme prime is: 49,394,034,691 for p <= 1,152,763
The 5,000th extreme prime is: 82,195,983,953 for p <= 1,500,973
The 30,000th extreme prime is: 4,889,328,757,567 for p <= 12,437,401
The 40,000th extreme prime is: 9,207,632,380,589 for p <= 17,245,391
The 50,000th extreme prime is: 15,118,097,491,121 for p <= 22,272,277
</pre>
 
1,969

edits