birthday.py 417 B

123456789101112131415161718192021
  1. #coding=utf-8
  2. '''
  3. Created on 2017年6月9日
  4. @vsersion:python3.6
  5. @author: liuyuqi
  6. '''
  7. from scipy.special import comb, perm
  8. from math import factorial
  9. #1-C(365,n)n!/(365)^n
  10. init=365;
  11. k=0;
  12. for n in range(4,init):
  13. pk=1-comb(365,n)*factorial(n)/pow(365,n);
  14. if pk>=0.5 :
  15. k=n;
  16. break;
  17. print(k)
  18. # perm(m, n) 排列数
  19. # comb(3, 2) 组合数
  20. # pow(a,b) n次方
  21. # factorial (x)阶乘