GerONSo

Untitled

Jan 16th, 2021 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. long long fact(int n) {
  6. long long res = 1;
  7. while(n > 1) {
  8. res *= n;
  9. n--;
  10. }
  11. return res;
  12. }
  13.  
  14. long double f(long double x, long double eps) {
  15. long double res = 0;
  16. long long i = 0;
  17. long long one = 1;
  18. long long fourPow = 1;
  19. long double xPow = 1;
  20. while(1) {
  21. long double cur = (one * fact(2 * i) * xPow) / ((1 - 2 * i) * fact(i) * fact(i) * fourPow);
  22. if(abs(cur) < eps) {
  23. return res;
  24. }
  25. i++;
  26. res += cur;
  27. fourPow *= 4ll;
  28. xPow *= x;
  29. one *= -1;
  30. }
  31. }
  32.  
  33. int main() {
  34. long double x, eps;
  35. cin >> x >> eps;
  36. cout << f(x, eps) << " " << sqrt(1 + x);
  37. return 0;
  38. }
Add Comment
Please, Sign In to add comment