Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int a,b,s1,s2;
  9. cin >> a >> b;
  10. if ((a % 2 == 0) && (b % 2 == 0)) {s1 = (a+b)/2 * ((b-a)/2 + 1); s2 = (a+1 + b - 1)/2 * ((b-a-2)/2 + 1); }
  11. if ((a % 2 != 0) && (b%2!=0)) {s1 = (a+b)/2 * ((b-a)/2 + 1); s2 = (a+1 + b - 1)/2 * ((b-a-2)/2 + 1); }
  12. if ((a % 2 != 0) && (b%2==0)) {s1 = (a+b+1)/2 * ((b-a-1)/2 + 1); s2 = (a+1 + b - 1)/2 * ((b-a-1)/2 + 1); }
  13. if ((a % 2 == 0) && (b%2!=0)) {s1 = (a+b+1)/2 * ((b-a-1)/2 + 1); s2 = (a+1 + b - 1)/2 * ((b-a-1)/2 + 1); }
  14. cout << s1-s2;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement