【Light OJ 1104】Birthday Paradox

来源:互联网 发布:制版软件 编辑:程序博客网 时间:2024/06/08 03:46

题目连接:点击打开链接


1104 - Birthday Paradox
   PDF (English)StatisticsForum
Time Limit: 2 second(s)Memory Limit: 32 MB

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.

Output

For each case, print the case number and the desired result.

Sample Input

Output for Sample Input

2

365

669

Case 1: 22

Case 2: 30

 


PROBLEM SETTER: JANE ALAM JAN



题意:找出最少N个人,满足N个人中生日在同一天的概率大于等于0.5

题解:要计算至少两个人的生日同天概率可以逆着算所有人不同天生日的概率小于0.5,那么人数就是x = 1 * (n - 1)/n * (n-2)/n * … 直到x是小于0.5的。

#include<cstdio>int n;int main(){int t,cas;while(scanf("%d",&t)!=EOF){for(int i=0;i<t;i++){scanf("%d",&n);double k=1.0;cas=0;while(k>0.5){cas++;k*=(n-cas)*1.0/n;}printf("Case %d: %d\n",i+1,cas);}}return 0;}