fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. double p_no_match = 1.0; // Probability that NO ONE shares a birthday
  5. int i = 0;
  6.  
  7. // We want the probability of a match (1 - p_no_match) to be >= 0.5
  8. // Which is the same as p_no_match being <= 0.5
  9. while (p_no_match > 0.5) {
  10. i++;
  11. // Multiply by (remaining days / total days)
  12. p_no_match *= (365.0 - i + 1) / 365.0;
  13. }
  14.  
  15. printf("Number of people needed: %d\n", i);
  16. return 0;
  17. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
Number of people needed: 23