請求解下面的積分並輸出答案:
輸入
多組輸入。
每一個樣例包含兩個正整數 a,b (0<a<=b<=10)
輸出
每一個樣例輸出一個整形,即積分的答案乘以10000。(精度爲 1e-5 ,每次取左端點)
樣例輸入
1 1
1 2
2 8
樣例輸出
0
6593
-312
解題思路:
由於的不定積分無法用初等函數求出。
於是我們可以想到泰勒公式
從而得到
對其積分
於是我們便可在的精度要求下求出定積分
代碼實現:
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-5;
double fun(double x){
double t=x,ans=x;
int n=1;
while(fabs(t)>=eps){ //精度要求
t=(-t*x*x)/((n+1)*(n+2));
ans+=t/(n+2);
n+=2;
}
return ans;
}
int main(){
double a,b;
while(~scanf("%lf%lf",&a,&b)){
double r1=fun(a),r2=fun(b); //F(b)-F(a)
printf("%d\n",(int)((r2-r1)*10000));
}
return 0;
}