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. java的线程中的Runnable

                      在java中可有两种方式实现多线程,一种是继承Thread类,一种是实现Runnable接口:Thread类是在java.lang包中定义的.一个类只要继承了Thr ...

  2. yum中baserul路径中的空格

    配置yum源时,比如指定本地挂载的光盘时,路径中包含空格.在不使用链接的情况下,用"\"进行转义不行,把路径加单.双引号也不可行.正确做法是把空格用%20代替.同理,其他不可识别的 ...

  3. 判断当前是否运行于Design Mode

    在使用Visual Studio设计XAML时,设计器运行在[设计时]状态.VS在内部运行这些代码,帮你把界面的类真实效果展示出来.一般情况下也不会有什么问题,但是当代码中存在外部资源时,XAML可能 ...

  4. Android 开源项目分类汇总

    Android 开源项目分类汇总 Android 开源项目第一篇——个性化控件(View)篇  包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView ...

  5. 我的博客模板(线框图wireframe)

    不久前看到一篇介绍定制网页浏览的方法,当时就想着,我把我的博客页也修改下,在手机浏览的时候,也能漂亮的显示出来.以后写的文章的话,也可以分享的微信朋友圈里面和朋友分享. 具体步骤参考:http://w ...

  6. 智捷公开课马上开始了-欢迎大家一起讨论学习-第一系列读《Swift开发指南(修订版) 》看Swift视频教程

    引用: 智捷课堂携手51CTO学院.图灵教育联合举办iOS线上培训就业班系列体验公开课. 分享移动开发.移动设计方向最新,最热,最抢眼技术热点以及设计经验.我们每周将最少举办一次公开课,同时会提前安排 ...

  7. <img>元素底部为何有空白?

    原因: 图片文字等inline元素默认是和父级元素的baseline对齐的,即:vertical-align 的默认值是 baseline:而baseline又和父级底边bottom有一定距离: im ...

  8. 勿在浮沙筑高台-- 关于IT技术学习的一点反思

    常常看到前辈们大牛们感慨, 感慨我们这一代人生活在最好的时代, 拥有海量的学习资源以及指数增长的新技术与新知识. 的确, 如果你是这个时代的大学生,或是初出茅庐的程序员, 你会发现有太多太多的选择,  ...

  9. frame和iframe区别

    1.frame不能脱离frameSet单独使用,iframe可以: 2.frame不能放在body中:如下可以正常显示: <!--<body>--> <frameset ...

  10. [GeekBand]C++高级编程技术(2)

    本篇笔记主要分为两个主要部分,第一部分关于对象模型,第二部分是关于new和delete的更加深入的学习. 一.对象模型 关于vptr(虚指针)和vtbl(虚函数表) 只要用到了虚函数,对象中就会多一个 ...