Strong and weak primes: Difference between revisions

Added 11l
(Changed countup(n * n, N, n) to countup(n * n, N, 2 * n).)
(Added 11l)
Line 34:
::*   The OEIS article [[oeis:A051635|A051635: weak primes]].
<br><br>
 
=={{header|11l}}==
<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 + 1).step(n)
is_prime[i] = 0B
R enumerate(is_prime).filter((i, prime) -> prime).map((i, prime) -> i)
 
V p = primes_upto(10'000'000)
[Int] s, w, b
L(i) 1 .< p.len - 1
I p[i] > (p[i - 1] + p[i + 1]) * 0.5
s [+]= p[i]
E I p[i] < (p[i - 1] + p[i + 1]) * 0.5
w [+]= p[i]
E
b [+]= p[i]
 
print(‘The first 36 strong primes: ’s[0.<36])
print(‘The count of the strong primes below 1,000,000: ’sum(s.filter(p -> p < 1'000'000).map(p -> 1)))
print(‘The count of the strong primes below 10,000,000: ’s.len)
print("\nThe first 37 weak primes: "w[0.<37])
print(‘The count of the weak primes below 1,000,000: ’sum(w.filter(p -> p < 1'000'000).map(p -> 1)))
print(‘The count of the weak primes below 10,000,000: ’w.len)
print("\n\nThe first 10 balanced primes: "b[0.<10])
print(‘The count of balanced primes below 1,000,000: ’sum(b.filter(p -> p < 1'000'000).map(p -> 1)))
print(‘The count of balanced primes below 10,000,000: ’b.len)
print("\nTOTAL primes below 1,000,000: "sum(p.filter(pr -> pr < 1'000'000).map(pr -> 1)))
print(‘TOTAL primes below 10,000,000: ’p.len)</lang>
 
{{out}}
<pre>
The first 36 strong primes: [11, 17, 29, 37, 41, 59, 67, 71, 79, 97, 101, 107, 127, 137, 149, 163, 179, 191, 197, 223, 227, 239, 251, 269, 277, 281, 307, 311, 331, 347, 367, 379, 397, 419, 431, 439]
The count of the strong primes below 1,000,000: 37723
The count of the strong primes below 10,000,000: 320991
 
The first 37 weak primes: [3, 7, 13, 19, 23, 31, 43, 47, 61, 73, 83, 89, 103, 109, 113, 131, 139, 151, 167, 181, 193, 199, 229, 233, 241, 271, 283, 293, 313, 317, 337, 349, 353, 359, 383, 389, 401]
The count of the weak primes below 1,000,000: 37780
The count of the weak primes below 10,000,000: 321749
 
 
The first 10 balanced primes: [5, 53, 157, 173, 211, 257, 263, 373, 563, 593]
The count of balanced primes below 1,000,000: 2994
The count of balanced primes below 10,000,000: 21837
 
TOTAL primes below 1,000,000: 78498
TOTAL primes below 10,000,000: 664579
</pre>
 
=={{header|ALGOL 68}}==
1,481

edits