sve_vash

Untitled

Jan 14th, 2020
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4.  
  5. long double findN(long double eps) {
  6. int n = 1;
  7. while (( pow(2.0, n + 1) / pow(n + 2, n + 1)) - eps < std::numeric_limits<double>::epsilon()) {
  8. n++;
  9. }
  10. return n + 1;
  11. }
  12.  
  13. int main() {
  14. long double eps;
  15. std::string str;
  16. std::cin >> str;
  17.  
  18. eps = stold(str);
  19.  
  20. auto N = findN(eps);
  21.  
  22. double res = 0;
  23. double sum = 0;
  24. for (auto i = 1; i <= N; i++) {
  25. res = (pow((-1.0), i) * pow(2.0, i)) / pow(i + 1, i);
  26. sum += res;
  27. }
  28.  
  29. std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
  30. std::cout.precision(str.length() - 2);
  31.  
  32. std::cout << sum << std::endl;
  33. return 0;
  34. }
RAW Paste Data