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.


IntList primes = new IntList();
 
void setup() {
  sieve(500);
  int count = 0;
  for (int i = 2; i < 500; i++) {
    if (primes.hasValue(i) && primes.hasValue(sumDigits(i))) {
      print(i + " ");
      count++;
    }
  }
  println();
  print("Number of additive primes less than 500: " + count);
}
 
int sumDigits(int n) {
  int sum = 0;
  for (int i = 0; i <= floor(log(n) / log(10)); i++) {
    sum += floor(n / pow(10, i)) % 10;
  }
  return sum;
}
 
void sieve(int max) {
  for (int i = 2; i <= max; i++) {
    primes.append(i);
  }
  for (int i = 0; i < primes.size(); i++) {
    for (int j = i + 1; j < primes.size(); j++) {
      if (primes.get(j) % primes.get(i) == 0) {
        primes.remove(j);
        j--;
      }
    }
  }
}