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

5.7k Views Asked by At

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?

3

There are 3 best solutions below

1
On

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.

0
On

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.

0
On

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