CF1080B题解
题目传送门。
由于题目有了样例解释,所以直接上思路。
显而易见,由于 ,所以设 为前 个数的和,则
所以 。
所以 。
当 为奇数呢?
众所周知,。
由此写出代码。
#include<iostream>
using namespace std;
int main(){
int n,l,r,ans1,ans2;
cin>>n;
while(n--){
cin>>l>>r;
if(r%2)ans2=(r+1)/2-(r+1);
else ans2=r/2;
if(l%2)ans1=(l-1)/2;
else ans1=l/2-l;
cout<<ans2-ans1<<endl;
}
return 0;
}

浙公网安备 33010602011771号