Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- long long fact(int n) {
- long long res = 1;
- while(n > 1) {
- res *= n;
- n--;
- }
- return res;
- }
- long double f(long double x, long double eps) {
- long double res = 0;
- long long i = 0;
- long long one = 1;
- long long fourPow = 1;
- long double xPow = 1;
- while(1) {
- long double cur = (one * fact(2 * i) * xPow) / ((1 - 2 * i) * fact(i) * fact(i) * fourPow);
- if(abs(cur) < eps) {
- return res;
- }
- i++;
- res += cur;
- fourPow *= 4ll;
- xPow *= x;
- one *= -1;
- }
- }
- int main() {
- long double x, eps;
- cin >> x >> eps;
- cout << f(x, eps) << " " << sqrt(1 + x);
- return 0;
- }
Add Comment
Please, Sign In to add comment