Definitions

   A   safe prime   is a prime   p   and where   (p-1)/2   is also prime.
   The corresponding prime  (p-1)/2   is known as a   Sophie Germain   prime.
   An   unsafe prime   is a prime   p   and where   (p-1)/2   isn't   a prime.
   An   unsafe prime   is a prime that   isn't   a   safe   prime.


Task

   Find and display (on one line) the first   35   safe primes.
   Find and display the   count   of the safe primes below   1,000,000.
   Find and display the   count   of the safe primes below 10,000,000.
   Find and display (on one line) the first   40   unsafe primes.
   Find and display the   count   of the unsafe primes below   1,000,000.
   Find and display the   count   of the unsafe primes below 10,000,000.
   (Optional)   display the   counts   and   "below numbers"   with commas.
Show all output here.



Related Task

   strong and weak primes.


Also see

   The OEIS article:     safe   primes.
   The OEIS article:   unsafe primes.


   NB. play around a bit to get primes less than ten million
   p:inv 10000000
664579

   p:664579
10000019

   PRIMES =: p:i.664579
   10 {. PRIMES
2 3 5 7 11 13 17 19 23 29

   {: PRIMES
9999991


   primeQ =: 1&p:
   safeQ =: primeQ@:-:@:<:
   Filter =: (#~`)(`:6)

   SAFE =: safeQ Filter PRIMES

   NB. first thirty-five safe primes
   (32+3) {. SAFE
5 7 11 23 47 59 83 107 167 179 227 263 347 359 383 467 479 503 563 587 719 839 863 887 983 1019 1187 1283 1307 1319 1367 1439 1487 1523 1619
   

   NB. first forty unsafe primes
   (33+7) {. PRIMES -. SAFE
   2 3 13 17 19 29 31 37 41 43 53 61 67 71 73 79 89 97 101 103 109 113 127 131 137 139 149 151 157 163 173 181 191 193 197 199 211 223 229 233
   

   NB. tally of safe primes less than ten million
   # SAFE
30657
   

   NB. tally of safe primes below a million
   # 1000000&>Filter SAFE
4324
   

   NB. tally of perilous primes below ten million
   UNSAFE =: PRIMES -. SAFE

   # UNSAFE
633922
   

   NB. tally of these below one million
   K =: 1 : 'm * 1000'
   +/ UNSAFE < 1 K K
74174
   
