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. 【python,排序】几种常用的排序算法,使用python实现

    1. 选择排序 -- -- def selectSort(l): for i in range(len(l)): j = i + 1 t_min = l[i] loc_min = i for j in ...

  2. 转:MediaCoder H.264格式编码参数设置及详解

    转: http://mediacoder.com.cn/node/81 由于现在大部分视频转码都选择H.264格式进行编码,同时CUDA编码的画质还达不到x264软编码的质量(如果你对画质无要求,可以 ...

  3. 关于inodes占用100%的问题及解决方法

    #df shows no file systems processedPosted by John Quaglieri on 27 July 2012 07:26 AMA df -m command ...

  4. TransmitFile下载文件(部分转载)

    例子代码: public void Down() { TransmitFile(@"/File/KBPub.zip"); } public void TransmitFile(st ...

  5. 如何把rtf、doc文件转换为HTML文件

    //retText是路径 1 public string ExtractHtml(string rtfText) { try { //Create word object Word.Applicati ...

  6. Android开发的十项注意

    随着移动平台的发展及其应用的不断改善,质量成为决定成败的关键.用户要求他们安装的应用响应快.性能好,如果某个应用不能提供卓越的功能和稳定的用户体验,那注定会被很快卸载: 尽管现在Android智能手机 ...

  7. spark HA 安装配置和使用(spark1.2-cdh5.3)

    安装环境如下: 操作系统:CentOs 6.6 Hadoop 版本:CDH-5.3.0 Spark 版本:1.2 集群5个节点 node01~05 node01~03 为worker. node04. ...

  8. sqlserver关于对列的权限控制

    -- 脚本新建登录数据库的用户 USE [master]GOCREATE LOGIN [sa1] WITH PASSWORD=N'123456', DEFAULT_DATABASE=[master], ...

  9. PHP JS判断浏览器,微信浏览器

      微信内置浏览器的 User Agent 如何判断微信内置浏览器,首先需要获取微信内置浏览器的User Agent,经过在 iPhone 上微信的浏览器的检测,它的 User Agent 是: Mo ...

  10. (转)如何构建高性能,稳定SOA应用之-负载均衡-Decoupled Invocation(一)

    当我们在为一个软件设计架构的时候,我们不仅仅要确保所做出来的架构要满足系统的业务需求,更加要确保做出来的架构要满足可维护性,安全,稳定性的非业务行的需求. 另外一个非常重要的非功能性需求就是性能.性能 ...