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

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.