I had a mistake in my original answer, here is a corrected version.
here is how you can calculate the probability that in a group of $23$ people exactly $3$ have the same birthday and the remaining $20$ persons all have different birthdays (so that there is a total of $21$ different birthdays).
- There are $23\choose{3} $ possibilities of fixing three people.
- The probability that three persons have the same birthday is $p_1 = \frac{365}{365^3}$.
- The probability that the remaining 20 persons have all a different birthday is $p_2 = \frac{364 \cdot \dots \cdot 345}{365^{20}}$.
Therefore we arrive at
$$
p = {23\choose 3} \cdot p_1 \cdot p_2 = 0.007395218.
$$
I also wrote a small R simulation:
library(dplyr)
bd3 <- function(){
x <- sample(1:365, 23, replace = T)
n1 <- table(x) %>% as.data.frame() %>% filter(Freq==3) %>% nrow()
n2 <- table(x) %>% as.data.frame() %>% filter(Freq==1) %>% nrow()
return(ifelse(n1 == 1 & n2 == 20, 1 ,0))
}
set.seed(118)
replicate(100000, bd3()) %>% mean
[1] 0.0074
So the result of the simulation is close to the theoretical answer.