Jump to content

Strong and weak primes: Difference between revisions

(Add Factor example)
Line 313:
 
The number of weak primes below 10,000,000 is 321,750
</pre>
 
=={{header|J}}==
<pre>
Filter =: (#~`)(`:6)
average =: +/ % #
 
 
NB. vector of primes from 2 to 10000019
PRIMES=:i.@>:&.(p:inv) 10000000
 
 
strongQ =: 1&{ > [: average {. , {:
STRONG_PRIMES=: (0, 0,~ 3&(strongQ\))Filter PRIMES
NB. first 36 strong primes
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
NB. tally of strong primes less than one and ten million
+/ STRONG_PRIMES </ 1e6 * 1 10
37723 320991
 
weakQ =: 1&{ < [: average {. , {:
weaklings =: (0, 0,~ 3&(weakQ\))Filter PRIMES
NB. first 37 weak primes
37 {. weaklings
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
NB. tally of weak primes less than one and ten million
+/ weaklings </ 1e6 * 1 10
37780 321750
</pre>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.