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.

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

题意:地球上一年是365天,在一个最聚会上,加上你自己有23个人....   在这23个人中,有两个生日是同一天的概率超过50%。

   现在要求你输入一年的天数,求在聚会上你还要邀请多少人,才可以使,有两个人生日是同一天的概率超过50%..

   例如,火星上一年是669天,那么他还要邀请30个人才使得概率超过50%

解题思路:既然是求两个人同一天的生日的概率,那么就是1-P(E)。这里的P(E)表示任何两个人的生日都不相同的概率

     1-P(E)=1-(n/n)  *  (n-1)/n  *  (n-2)/n   *......... *   (n-(m-1))/n

     这里的m表示m个人.....

代码如下 :

 #include <stdio.h>
double birthday(int n)
{
double ans=1.0;
int m=;
for(int i=; ; i++)
{
ans*=(double)(n-i)/n;
m++;
if(1.0-ans>=0.5)
break;
}
return m;
}
int main()
{
int T,N=;
scanf("%d",&T);
while(T--)
{
N++;
int n;
scanf("%d",&n);
int ans=birthday(n);
printf("Case %d: %d\n",N,ans-);
}
return ;
}

随机推荐

  1. js 回车键 跳转到下一个输入框

    window.document.onkeydown(){ if(event.keyCode==13) event.keyCode=9; }

  2. 如何解决firefox下window.event的问题

    一.在函数中传递event参数 在函数中传递event参数,这样我们就可以兼容IE和FF的event的获取了,如下面的函数: function _test(evt){    var src = evt ...

  3. linux 命令行发送邮件及附件

    环境 本机安装sendmail了, 但是没有启动. 其他机器上有mail server, 并且已经把本机加到open relay列表中了, 可以通过该mail server发送邮件.做法如下:1. 安 ...

  4. TCP/IP TIME_WAIT状态

    百度运维部二面面试官问我这个 我直接懵逼了 TIME_WAIT状态是通信双方简历TCP连接后, 主动关闭的一方就会进入TIME_WAIT状态 1.client向server发送FIN(M),clien ...

  5. hdu 4669 模拟

    思路: 主要就是模拟这些操作,用链表果断超时.改用堆栈模拟就过了 #include<map> #include<set> #include<stack> #incl ...

  6. 转:云风skynet服务端框架研究

    转:  http://forthxu.com/blog/skynet.html skynet是云风编写的服务端底层管理框架,底层由C编写,配套lua作为脚本使用,可换python等其他脚本语言.sky ...

  7. ListViewDemo

    ListView Layout示例:MainActivity.java中定义待显示的数据countryArray, 在activity_main中定义ListView,activity_listvie ...

  8. hdu 1222 Wolf and Rabbit

    Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbi ...

  9. DWZ (JUI) 教程 DWZ中dialog层的刷新

    在DWZ开发过程中经常会遇到的一种情况就是:在navTab页面中通过a标签打开一个dialog,在dialog层进行操作后,需要对该dialog层进行必要的刷新操作. 1.首先讲一下思路: 在非dia ...

  10. php中simplexml_load_string使用实例

    先用一段代码重现一下问题 乍一看,结果很让人费解: 代码如下 复制代码 <?php $string = <<<EOF <data> <foo><b ...