CF#524-B
题目链接
http://codeforces.com/contest/1080/problem/B
思路
数学规律题
代码
1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int n; 6 while(cin >> n) 7 { 8 int l, r; 9 while(n--) 10 { 11 int ans = 0; 12 cin >> l >> r; 13 if(l & 1) 14 ans = ((r - l + 1) & 1) ? ((r - l) / 2 - r) : (r - l + 1) / 2; 15 else 16 ans = ((r - l + 1) & 1) ? (-(r - l) / 2 + r) : (-(r - l + 1) / 2); 17 cout << ans << endl; 18 } 19 } 20 return 0; 21 }