A password consists of four distinct digits such that their sum is 19 and such that exactly two of these digits are prime, for example 0397. The number of possibilities for the password is?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
So primes here are 2, 3,5, 7.
Taking 2,3, you need 14 more to get a sum of 19. This can be done with 6,8 only.
Taking 2,5, you need 12 more to get a sum of 19. This can be done with 4,8 only.
Taking 2,7, you need 10 more to get a sum of 19. This can be done with 1,9 or 4,6 only.
Taking 3,5, you need 11 more to get a sum of 19. This cannot be done.
Taking 3,7, you need 9 more to get a sum of 19. This can be done with 1,8 or 0,9 only.
Taking 5,7, you need 7 more to get a sum of 19. This can be done 1,6 only.
That gives us 6 sets each represents $4!=24$ combinations, so there are 7*24=168 possible passwords.
Here is a python snippet
Here is the output
Well, we have 2, 3, 5, and 7 as our primes. Take 2 and 3. Now the problem reduces to finding $X$ and $Y$ in $23XY$ so that $2 + 3 + X + Y = 19$, $X \ne Y$, $X \ne 2$, $X \ne 3$, $Y \ne 2$, and $Y \ne 3$. You could do this by hand if you are systematic. Repeat the same process for 2 and 5, 2 and 7, etc. You could also write a Java program or ask for help at Programmers.
So $4! \times 7 = 168$ possibilities