Submit Status

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

每个人都有自己的生日,如果一群人站在一起,那么他们有至少两个人生日相同的概率是多少? 例如有任意22个人站在一起,概率就能达到0.5

所以问你给出一年的时间长(不一定是365天,有可能是火星来的),需要选出至少多少人才能使概率不低于0.5

方法:选N个人,这一群人生日都不相同的概率是P=364/365+363/365+362/365.........

最后使得P小于等于0.5就行了

#include"iostream"
#include"cstdio"
using namespace std;
int main()
{
int T,ca=;
cin>>T;
while(T--)
{
int year,sel;
cin>>year;
sel=year;
int ans=;
double p=1.0;
while(p>0.5)
{
ans++;
sel--;
p*=(sel*1.0)/year;
}
printf("Case %d: %d\n",ca++,ans);
}
return ;
}

O(O_O)O

最新文章

  1. Struts——(四)异常处理机制
  2. [转]MongoDB密码设置(基于windows)
  3. php大力力 [038节] 全栈工程师的含义
  4. Cannot find SS.INI file for user *** 解决方法
  5. maven 常用5个命令
  6. ThinkPHP:读取数据库数据 (2)
  7. 摘录知乎上关于android开发的话题精华
  8. ActiveMQ(5.10.0) - JNDI Support
  9. [状压dp]HDU5045 Contest
  10. 写个自己的Xcode4插件
  11. android Bluetooth(官方翻译)
  12. qt事件传递过程和处理
  13. HDU1024 Max Sum Plus Plus(DP)
  14. drawable文件夹详解
  15. Packer piplines and workflow
  16. Python基础【day03】:字典进阶(二)
  17. Big Event in HDU (母函数, 玄学AC)
  18. 慢查询日志和profiling
  19. Day1 Excel基本知识
  20. 为 HTTP/2 头压缩专门设计的 HPACK

热门文章

  1. [Usaco2003 Open]Lost Cows
  2. A - Add More Zero
  3. 贪心 Codeforces Round #173 (Div. 2) B. Painting Eggs
  4. 贪心 Codeforces Round #109 (Div. 2) B. Combination
  5. ORA-00845错误原因及解决办法
  6. ABP教程(一)- ABP介绍
  7. 阿里云OSS搭建移动应用直传服务的.Net C#示例
  8. java之java.lang.UnsupportedClassVersionError:com/mysql/jdbc/Driver : Unsupported major.minor version 52.0
  9. Windows远程桌面连接复制文件失败或非常慢
  10. 从源码对比DefaultServeMux 与 gorilla/mux