... and one should include the pigeonhole principle: pbirthday2 <- function(n, classes = 365) { c <- classes # as pbirthday() if(n >= 2) { if(n > classes) 1 else -expm1(sum(log1p(-(1:(n-1))/classes))) } else 0 }