Birthday Paradox lightoj 1104 Birthday paradox (probability)

Source: Internet
Author: User

Description

Sometimes some mathematical results is hard to believe. One of the common problems is the birthday paradox. Suppose you is in a party where there is people including you. What's the probability that at least and the party has same birthday? Surprisingly the result is more than 0.5. Now this is the opposite. You are given the number of days in a year. Remember that's you can are in a different planet, for example, in Mars, and a year are669 days long. You has to find the minimum number of people you has to invite in a party such that the probability of at least B peop The Le in the party has 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 plan Et.

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

Test instructions: Ask at least two people for birthdays on the same day as the probability of asking how many individuals you have invited

Analysis: See at least two words, we certainly think of the need to ask two people are not on the same day the probability of birthdays. If the first person on the birthday of a day, the probability is 1, the second person's birthday choice probability is only 364/365, the third person's birthday choice probability is 363/365 ... and so on. So the probability is 1*364/365*363/365 ...

Note: Ask how many people you invite, so the final answer will be minus 1.

#include <iostream>#include<stdio.h>#include<string.h>#include<string>#include<vector>#include<algorithm>#include<map>#include<queue>#include<stack>#include<math.h>using namespacestd;#defineINF 0x3f3f3f3fConst intMAXN =4007; typedefLong LongLL;intMain () {intT, N, K, cnt=1; Doubleans; scanf ("%d", &T);  while(T--) {scanf ("%d", &N); K=0; Ans=1;  while(1-ans<0.5) {ans*= (n-k) *1.0/N; K++; } printf ("Case %d:%d\n", cnt++, K-1); }    return 0;}
View Code

Birthday Paradox lightoj 1104 Birthday paradox (probability)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.