What is the probability of exactly two out of n persons sharing a birthday? The classical Birthday problem asks for the probability of at least two out of $n$ people sharing the same birthday or sometimes for the least amount $n$ of people required such that with a probability of 50% at least two of them share their birthday. But what about the question how probable it is that also no more than two people share their birthday?
$\mathbb{P}$(no more than two people share their birthday) = $\mathbb{P}$(noone shares their birthday with anyone else) + $\mathbb{P}$(noone shares their birthday with anyone else except one pair)

Now,


$\mathbb{P}$(noone shares their birthday with anyone else) = $\frac{365!}{(365 -n)!}*\frac{1}{365^n}$
$\mathbb{P}$(noone shares their birthday with anyone else except one pair) = $\frac{364!}{(364 - \overline{n-2})!}*\left({n \choose 2} 365\right)*\frac{1}{365^n}$.
n people and only two share a birthday.
Approach: Consider that $n-1$ don't share birthday with anyone. (everyone knows this) $(1)$
The last person will have to share birthday with anyone of the $n-1$ people.
The same has to be done for the initial $n-1$ people who didn't share birthdays.
This will give a sum of $ (n-1) + (n-2) + (n-3) + \dots + \big(n-(n-1)\big) = \frac { n (n-1) } 2 $ $(2)$.
Answer $ = (1) * (2) $