Skip to content

Commit 2ce3a28

Browse files
committed
Margarite and the best present
1 parent f1943e9 commit 2ce3a28

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

1080B.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define ll long long
5+
#define '\n' endl
6+
#define debug(n) cout<<(n)<<endl;
7+
const ll INF = 2e18 + 99
8+
9+
int main(){
10+
ios_base::sync_with_stdio(false);
11+
cin.tie(NULL);
12+
13+
int t;
14+
cin>>t;
15+
long long l, r;
16+
while(t--){
17+
18+
cin>>l>>r;
19+
long long odd_l, odd_r;
20+
l--;
21+
if(l % 2 == 0){
22+
odd_l = l/2 * l/2;
23+
}
24+
else{
25+
odd_l = (l/2 + 1) * (l/2 + 1);
26+
}
27+
long long even_l = l/2 * (l/2 + 1);
28+
if(r % 2 == 0){
29+
odd_r = r/2 * r/2;
30+
}
31+
else{
32+
odd_r = (r/2 + 1) * (r/2 + 1);
33+
}
34+
long long even_r = r/2 * (r/2 + 1);
35+
36+
long long even_s = even_r - even_l;
37+
long long odd_s = odd_r - odd_l;
38+
39+
cout<<(even_s - odd_s)<<"\n";
40+
}
41+
return 0;
42+
}

0 commit comments

Comments
 (0)