Advertisement
Guest User

Untitled

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