We, count all ways we can get the cards, minus the combination where we don't get pairs of Aces and eights, there are 3 cases:
1. Only pair of Aces
2. Only pair of Eights
3. No pair of Aces or eights.
The total combination we could get is 52C5
For the first case, we have 3 cases:
case 1. There are two Aces
in this case, we also have two cases:
a. there is exactly one Eight
then the number of combination is 4C2(for the Aces) * 4(the Eight) * 44 * 43 (for the other two cards, as Aces and Eights can't be used anymore)
b. There is no eight.
then the number of combination is 4C2(for the Aces) * 44 * 43 * 42( for three other cards, no aces or eights)
The total number on case 1 is 4C2 * 44 * 43 * 46
case 2: There are three Aces
Similar with previous case, we have two cases:
a. There is exactly one Eight
then the number of combination of this case is 4C3(for the Aces) * 4(for the eight) * 44(for the last card, no Aces or Eights)
b. There is no Eights
then the number of combination of this case is 4C3(for the Aces) * 44 * 43 (for the other two cards, no Aces or Eights)
So total number of combination in case 2 is 4C3 * 44 * 47
case 3: There are 4 Aces
we have the number of combination is 4C4(for the Aces) * 48(for the last cards, no Aces)
Then total number of combination on case "There are only pair of Aces" is 6 * 44 * 43 * 46 + 4 * 44 * 47 + 1 * 48, call it as X
For the case "there are only pair of eights", we have the same calculation with previous case, so the total is also X.
For the case "There are no Aces or Eights" we have the number of combination is 44 * 43 * 42 * 41 * 40 (5 cards with no Aces or Eights)
So the answer to your question is 52C5 - 2X - (44 * 43 * 42 * 41 * 40)