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

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.