Description
Sometimes some mathematical results are hard to believe. One of the common problems is the birthday paradox. Suppose you are in a party where there are 23 people including you. What is the probability that at least two people in the party have same birthday? Surprisingly the result is more than 0.5. Now here you have to do the opposite. You have given the number of days in a year. Remember that you can be in a different planet, for example, in Mars, a year is 669 days long. You have to find the minimum number of people you have to invite in a party such that the probability of at least two people in the party have same birthday is at least 0.5.
INPUT
Input starts with an integer T (≤ 20000), denoting the number of test cases.
Each case contains an integer n (1 ≤ n ≤ 105) in a single line, denoting the number of days in a year in the planet.
For each case, print the case number and the desired result.
Sample Input
2
365
669
Sample OutputCase 1: 22
Case 2: 30
题解:题目让求至少邀请多少人使得至少两个人的生日在同一天的概率不小于0.5。设为x人,则需要求 2个人同一天生日的概率+3个人同一天生日的概率+...+x个人同一天生日的概率。这样求当然是不可取的,反过来,只要求出x个人的生日都不在同一天的概率使其最大化的 <0.5就好了。x个人的生日情况有(每年的天数)^x (例:365^x),而所有人的生日都不在同一天的情况进行全排就能得到:A(天数,x),1-A(天数,x)/(每年的天数)^x>=0.5的x的最大值即为所求。
<span style="font-family:SimSun;">#include<cstdio>
int main()
{
int t,cnt=1;
double m,n,sum;
scanf("%d",&t);
while(t--)
{
scanf("%lf",&n);
m=n,sum=1;
int x=0;
while(1)
{
sum*=(m-1)/n;
x++;m-=1;
if(sum<=0.5)
break;
}
printf("Case %d: %d\n",cnt++,x);
}
return 0;
}</span>