πŸ’‘ Birthday Paradox

TESTCASE # 6 : no-output (Time: 0 s)

#include<iostream>
using namespace std;
int main()
{
    long double p,ans=1.0;
    cin>>p;
    int i,c=0;
    p=(1-p);
    for(i=365;i>0;i--)
    {
        ans=(ans*i)/365;
        c++;
        if(ans<=p)
        {
         cout<<c;
         break;
        }
    }
    return 0;
}

You need to do this: Its a direct formula:
ceil(sqrt(1.02365*log(1/(1-p))))

Use this formula to pass all test cases.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

plz run this one’s this is throw wrong answer.

When n=1 , we directly print 366.
Else we use this formula bro.

You can have a look at this implementation if you still face any issue.

1 Like