SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int a, b, ans0 = 0, ans1 = 0, n;
  6.     cin >> a >> b;
  7.     if (a % 2 == 0 && b % 2 == 1) {
  8.         n = (b - a + 1) / 2;
  9.         ans0 = (a + n - 1)*n;
  10.         ans1 = (a + n)*n;
  11.     }
  12.     else if (a % 2 == 0 && b % 2 == 0) {
  13.         n = (b - a + 1) / 2;
  14.         ans0 = (a + n)*(n + 1);
  15.         ans1 = (a + n)*n;
  16.     }
  17.     else if (a % 2 == 1 && b % 2 == 0) {
  18.         n = (b - a + 1) / 2;
  19.         ans1 = (a + n - 1)*n;
  20.         ans0 = (a + n)*n;
  21.     }
  22.     else if (a % 2 == 1 && b % 2 == 1) {
  23.         n = (b - a + 1) / 2;
  24.         ans1 = (a + n)*(n + 1);
  25.         ans0 = (a + n)*n;
  26.     }
  27.     cout << ans0 - ans1 << endl;
  28.         return 0;
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top