

Definitions   (as per number theory)

   The   prime(p)   is the    pth   prime.
   prime(1)   is   2
   prime(4)   is   7
   A    strong   prime   is when     prime(p)   is   >   [prime(p-1) + prime(p+1)] ÷ 2
   A     weak    prime   is when     prime(p)   is   <   [prime(p-1) + prime(p+1)] ÷ 2


Note that the definition for   strong primes   is different when used in the context of   cryptography.



Task

   Find and display (on one line) the first   36   strong primes.
   Find and display the   count   of the strong primes below   1,000,000.
   Find and display the   count   of the strong primes below 10,000,000.
   Find and display (on one line) the first   37   weak primes.
   Find and display the   count   of the weak primes below   1,000,000.
   Find and display the   count   of the weak primes below 10,000,000.
   (Optional)   display the   counts   and   "below numbers"   with commas.
Show all output here.



Related Task

   Safe primes and unsafe primes.


Also see

   The OEIS article A051634: strong primes.
   The OEIS article A051635: weak primes.


   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
