# Three-digit numbers whose digits and digit sum are all prime

How many 3-digit numbers are there such that each of the digits is prime, and the sum of the digits is prime?

Shouldn't it be $0$, because the only one digit primes are $2,3,5,7$, and so the possible combinations of those numbers are (not particularly in primes) $235, 237, 257, 357$? And not one single group's digits add up to any prime number. But then why'd $0$ be a wrong answer?

• What about $335$? – 5xum Mar 7 '16 at 14:26
• so... I came up with the answer 7, (223, 227, 353, 557, 757, 337, 773) did anyone else come up with the same answer? Just want to check if I got this right. – jjhh Mar 7 '16 at 14:57
• I came up with more than $7$. For example, $223$ is missing from your list. – 5xum Mar 7 '16 at 15:04
• um, no, because 223 is the first number in the list (in brackets) – jjhh Mar 9 '16 at 8:30
• Sorry, I meant $227$. That one is missing from your list – 5xum Mar 9 '16 at 8:41

Here's a small hint: $335$ is one such number.
So $0$ is a wrong answer indeed.

It is not said that you cannot repeat digits.

• ooops... read it over so many times but never realised that... thank you – jjhh Mar 7 '16 at 14:41

The smallest sum is $2+2+2=6$.

The largest sum is $7+7+7=21$.

So the only possible prime sums are $7,11,13,17,19$:

• A sum of $7$ can be generated from the $3$ permutations of $223$
• A sum of $11$ can be generated from the $6$ permutations of $227$ and $353$
• A sum of $13$ can be generated from the $6$ permutations of $337$ and $355$
• A sum of $17$ can be generated from the $6$ permutations of $377$ and $557$
• A sum of $19$ can be generated from the $3$ permutations of $577$

Hence there are $3+6+6+6+3=24$ such numbers.

A short Python script in order to confirm the above:

count = 0

for a in [2,3,5,7]:
for b in [2,3,5,7]:
for c in [2,3,5,7]:
if a+b+c in [7,11,13,17,19]:
count += 1

print count


No, one such number is $223$. Now, there are $4^3$ $3$-digit numbers with digits $2, 3, 5, 7$, but since the conditions are independent of the order of the digits, it's enough to check just the $20$ such numbers whose digits are nondecreasing. Moreover, the sum of the three digits of any number will be $> 2$ and so if it is prime, it will be odd, and in particular must have an even number of $2$'s, so we need only check $12$ numbers: $223, 225, 227, 333, 335, \ldots$.

For example, $2 + 2 + 3 = 7$ is prime, so the $3$-digit numbers $223, 232, 322$ all have the desired property.