LightOJ1104---Birthday Paradox

来源:互联网 发布:windows怎么升级版本 编辑:程序博客网 时间:2024/04/30 06:09

LightOJ1104---Birthday Paradox 

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
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


找不相同的概率,用1减去,一直减下去直到小于0.5,剩下的自然是可能的概率大于0.5了,输出这个时候的n,别忘了减去自己。1的话特判输出1。


#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#include<iostream>using namespace std;int main(){double n,day;int t,text = 1;scanf("%d",&t);while(t--){n = 0;scanf("%lf",&day);if(day == 1){printf("Case %d: 1\n",text++);continue;}n = 1;for(int i=1; i<day; i++){n = n*(day-i)/day;if(n<=0.5){printf("Case %d: %d\n",text++,i);break;}}}return 0;}



0 0
原创粉丝点击