Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- long double findN(long double eps) {
- int n = 1;
- while (( pow(2.0, n + 1) / pow(n + 2, n + 1)) - eps < std::numeric_limits<double>::epsilon()) {
- n++;
- }
- return n + 1;
- }
- int main() {
- long double eps;
- std::string str;
- std::cin >> str;
- eps = stold(str);
- auto N = findN(eps);
- double res = 0;
- double sum = 0;
- for (auto i = 1; i <= N; i++) {
- res = (pow((-1.0), i) * pow(2.0, i)) / pow(i + 1, i);
- sum += res;
- }
- std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
- std::cout.precision(str.length() - 2);
- std::cout << sum << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement