Erdős-primes: Difference between revisions

Added 11l
(Added Algol 68)
(Added 11l)
Line 15:
:*   the OEIS entry:   [http://oeis.org/A064152 A064152 Erdos primes].
<br><br>
 
=={{header|11l}}==
{{trans|Nim}}
 
<lang 11l>F primes_upto(limit)
V is_prime = [0B] * 2 [+] [1B] * (limit - 1)
L(n) 0 .< Int(limit ^ 0.5 + 1.5)
I is_prime[n]
L(i) (n * n .. limit).step(n)
is_prime[i] = 0B
R is_prime
 
V is_prime = primes_upto(1'000'000)
V primeList = enumerate(is_prime).filter((i, prime) -> prime).map((i, prime) -> i)
 
[Int] factorials
L(n) 1..
I factorial(n) >= 1'000'000
L.break
factorials.append(factorial(n))
 
F isErdosPrime(p)
L(f) :factorials
I f >= p
L.break
I :is_prime[p - f]
R 0B
R 1B
 
[Int] erdosList2500
L(p) primeList
I p >= 2500
L.break
I isErdosPrime(p)
erdosList2500.append(p)
 
print(‘Found ’erdosList2500.len‘ Erdos primes less than 2500:’)
L(prime) erdosList2500
V i = L.index
print(‘#5’.format(prime), end' I (i + 1) % 10 == 0 {"\n"} E ‘ ’)
print()
 
V count = 0
L(p) primeList
I isErdosPrime(p)
count++
I count == 7875
print("\nThe 7875th Erdos prime is "p‘.’)
L.break</lang>
 
{{out}}
<pre>
Found 25 Erdos primes less than 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
 
The 7875th Erdos prime is 999721.
</pre>
 
=={{header|Action!}}==
1,481

edits