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.


proc sieve([*] bool prime) void:
    word max, p, c;
    max := dim(prime,1)-1;
    prime[0] := false;
    prime[1] := false;
    for p from 2 upto max do prime[p] := true od;
    for p from 2 upto max/2 do
        for c from p*2 by p upto max do
            prime[c] := false
        od
    od
corp
 
proc digit_sum(word num) byte:
    byte sum;
    sum := 0;
    while
        sum := sum + num % 10;
        num := num / 10;
        num /= 0
    do od;
    sum
corp
 
proc main() void:
    word MAX = 500;
    word p, n;
    [MAX]bool prime;
    sieve(prime);
    n := 0;
    for p from 2 upto MAX-1 do
        if prime[p] and prime[digit_sum(p)] then
            write(p:4);
            n := n + 1;
            if n % 20 = 0 then writeln() fi
        fi
    od;
    writeln();
    writeln("There are ", n, " additive primes below ", MAX)
corp