Number of possible passwords 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?
 A: 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.
A: Here is a python snippet
primes = [2,3,5,7]
others = [0,1,4,6,8,9]
npasswords = 0
for i in primes:
  for j in primes:
    if i < j:
      for k in others:
        l = 19-i-j-k
        if l < k and l >=0 and l not in primes:
          print("%d %d %d %d" % (i,j,k,l))
          npasswords += 24 # add !4 for all permutations
print("found %d passwords" % npasswords)

Here is the output
2 3 8 6
2 5 8 4
2 7 6 4
2 7 9 1
3 7 8 1
3 7 9 0
5 7 6 1
found 168 passwords

A: 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.
A: By hand 
p1 p2 remaining other pairs
2  3     14         6,8
2  5     12         4,8 
2  7     10      1,9  4,6      
3  5     11          -   
3  7      9      0,9   1,8  
5  7      7         1,6

So $4! \times 7 = 168$ possibilities 
