Erdős-primes
1
func is_erdos_prime(p) {
2
3
return true if p==2
4
return false if !p.is_prime
5
6
var f = 1
7
8
for (var k = 2; f < p; k++) {
9
p - f -> is_composite || return false
10
f *= k
11
}
12
13
return true
14
}
15
16
say ("Erdős primes <= 2500: ", 1..2500 -> grep(is_erdos_prime))
17
say ("The 7875th Erdős prime is: ", is_erdos_prime.nth(7875))
Copied!

Output:

1
Erdős primes <= 2500: [2, 101, 211, 367, 409, 419, 461, 557, 673, 709, 769, 937, 967, 1009, 1201, 1259, 1709, 1831, 1889, 2141, 2221, 2309, 2351, 2411, 2437]
2
The 7875th Erdős prime is: 999721
Copied!
Last modified 4mo ago
Copy link
Contents
Output: