-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1080_B.cpp
61 lines (46 loc) · 1.07 KB
/
1080_B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int t,a,b,n,n1,n2,odd,even;
cin>>t;
while(t--)
{
cin>>a>>b;
n=(b-a)+1;
if(a%2==0 && b%2==0)
{
n1=(n/2)+1;
even=n1*(a+b)/2;
//cout<<n1<<endl;
//cout<<even<<endl;
n2=n/2;
odd=n2*((a+1)+(b-1))/2;
//cout<<odd<<endl;
cout<<even-odd<<endl;
}
else if(a%2==1 && b%2==1)
{
n1=(n/2)+1;
odd=n1*(a+b)/2;
n2=n/2;
even=n2*((a+1)+(b-1))/2;
cout<<even-odd<<endl;
}
else if(a%2==0 && b%2==1)
{
n1=n/2;
even=n1*(a+(b-1))/2;
odd=n1*((a+1)+b)/2;
cout<<even-odd<<endl;
}
else if(a%2==1 && b%2==0)
{
n1=n/2;
even=n1*((a+1)+b)/2;
odd=n1*(a+(b-1))/2;
cout<<even-odd<<endl;
}
}
return 0;
}