fork download
  1. #include <iostream>
  2. #include <cmath>
  3. long M(double x, double p_min, long n)
  4. {
  5. n--;
  6. double p = 1;
  7. double b = std::pow(x, n + 1);
  8. long m = n;
  9.  
  10. while (p > 1 - p_min)
  11. {
  12. p = p - b;
  13. m++;
  14. b = b * (1 - x) * ((double)m / (m - n));
  15. }
  16.  
  17. return m;
  18. }
  19.  
  20. int main() {
  21. std::cout << M(0.25, 0.3, 2);
  22. }
Success #stdin #stdout 0s 3344KB
stdin
Standard input is empty
stdout
5