Description
计算 ∑k=lr1k2+k
Input
第一行一整数
T
表示用例组数,每组用例输入两个整数
Output
对于每组用例输出答案,误差不超过 10−9
Sample Input
3
1 2
34 76
4 4
Sample Output
0.666666666667
0.016424751719
0.050000000000
Solution
∑k=lr1k2+k=∑k=lr(1k−1k+1)=1l−1r+1
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100001;
int main()
{
int T;
ll l,r;
scanf("%d",&T);
while(T--)
{
scanf("%I64d%I64d",&l,&r);
double ans=1.0/l-1.0/(r+1);
printf("%.10f\n",ans);
}
return 0;
}