Definitions
In mathematics, additive primes are prime numbers for which the sum of their decimal digits are also primes.



Task
Write a program to determine (and show here) all additive primes less than 500.

Optionally, show the number of additive primes.



Also see

   the OEIS entry:   A046704 additive primes.
   the prime-numbers entry:   additive primes.
   the geeks for geeks entry: additive prime number.
   the prime-numbers fandom: additive primes.


import math, strutils
 
const N = 499
 
# Sieve of Erathostenes.
var composite: array[2..N, bool]  # Initialized to false, ie. prime.
 
for n in 2..sqrt(N.toFloat).int:
  if not composite[n]:
    for k in countup(n * n, N, n):
      composite[k] = true
 
 
func digitSum(n: Positive): Natural =
  ## Compute sum of digits.
  var n = n.int
  while n != 0:
    result += n mod 10
    n = n div 10
 
 
echo "Additive primes less than 500:"
var count = 0
for n in 2..N:
  if not composite[n] and not composite[digitSum(n)]:
    inc count
    stdout.write ($n).align(3)
    stdout.write if count mod 10 == 0: '\n' else: ' '
echo()
 
echo "\nNumber of additive primes found: ", count