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.


arraybase 1
max = 1000000
sc1 = 0: usc1 = 0: sc2 = 0: usc2 = 0
safeprimes$ =""
unsafeprimes$ = ""
 
redim criba(max)
# False = prime, True = no prime
criba[0] = True
criba[1] = True
 
for i = 4 to max step 2
  criba[i] = 1
next i
for i = 3 to sqr(max) +1 step 2
  if criba[i] = False then
    for j = i * i to max step i * 2
      criba[j] = True
    next j
  end if
next
 
usc1 = 1
unsafeprimes$ = "2"
for i = 3 to 3001 step 2
  if criba[i] = False then
    if criba[i \ 2] = False then
      sc1 += 1
      if sc1 <= 35 then safeprimes$ += " " + string(i)
    else
      usc1 += 1
      if usc1 <= 40 then unsafeprimes$ +=  " " + string(i)
    end if
  end if
next i
 
for i = 3003 to max \ 10 step 2
  if criba[i] = False then
    if criba[i \ 2] = False then
      sc1 += 1
    else
      usc1 += 1
    end if
  end if
next i
 
sc2 = sc1
usc2 = usc1
for i = max \ 10 + 1 to max step 2
  if criba[i] = False then
    if criba[i \ 2] = False  then
      sc2 += 1
    else
      usc2 += 1
    end if
  end if
next i
 
print "the first 35 Safeprimes are: "; safeprimes$
print
print "the first 40 Unsafeprimes are:  "; unsafeprimes$
print
print "     Safeprimes   Unsafeprimes"
print "  Below  -------------------------"
print max \ 10, sc1, usc1
print max   , sc2, usc2
end