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 is669 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

2

365

669

Sample Output

Case 1: 22

Case 2: 30

 

 

题意:求至少有两个人生日在同一天的概率,问你至少邀请多少个人

 

分析:看见至少两个字,我们当然想起来需要求两个人都不在同一天生日的概率了。若第一个人生日任选一天,概率为1,第二个人生日选择的概率只能为364/365,第三个人生日选择的概率为363/365......以此类推。。那么概率为1*364/365*363/365...

 

注意:问你邀请多少个人,所以最终答案要减1.

 

 

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

#define INF 0x3f3f3f3f
const int maxn = 4007;

typedef long long LL;


int main()
{
    int T, n, k, cnt=1;
    double ans;

    scanf("%d", &T);

    while(T --)
    {
        scanf("%d", &n);
        k = 0;
        ans = 1;

        while(1-ans<0.5)
        {
            ans *= (n-k)*1.0/n;
            k ++;
        }

        printf("Case %d: %d\n", cnt++, k-1);
    }
    return 0;
}
View Code

 

 

 

posted on 2016-08-13 20:19  不忧尘世不忧心  阅读(194)  评论(0编辑  收藏  举报