Codeforces 1080B. Margarite and the best present Solution
Solve in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
int r,a,b,t;
cin>>t;
while(t--)
{
cin>>a>>b;
if((a%2==0)&&(b%2==0))
{
r=(a+b)/2;
cout<<r<<endl;
}
if((a%2==1)&&(b%2==1))
{
r=-1*(a+b)/2;
cout<<r<<endl;
}
if((a%2==0)&&(b%2==1))
{
r=-1*(((b-a)+1)/2);
cout<<r<<endl;
}
if((a%2==1)&&(b%2==0))
{
r=(((b-a)+1)/2);
cout<<r<<endl;
}
r=0;
}
}
No comments