Birthday Paradox in C++

C++Server Side ProgrammingProgramming

The birthday paradox is a very famous problem in the section of probability. The problem statement of this problem is stated as,

There are several people at a birthday party, some are having the same birthday collision. We need to find the approximate no. of people at a birthday party on the basis of having the same birthday.

In the probability we know that the chance of getting ahead is 1/2 same as if we have some coins, the chance of getting 10 heads is 1/100 or 0.001.

Let us understand the concept,

The chance of two people having the different birthday is,

364/365 which is 1-1/365 in a Non-leap year.

Thus we can say that the first person having the probability of a specific birthday is ‘1’ and for others, it would be different which is,

P(different)= 1×(1-1/365)× (1-2/365)× (1-3/365) × (1-4/365).......

Thus P(same)= 1- P(different)

For Example,

No. of people having the same birthday for which probability is 0.70.

N= √2×365×log(1-1/p).

N= √2×365×log(1-1/0.70)= 30

Thus total approximate no. of people having the same birthday is 30.


 Live Demo

using namespace std;
int findPeople(double p){
   return ceil(sqrt(2*365*log(1/(1-p))));
int main(){


Published on 05-Feb-2021 05:45:11