Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- int a,b,s1,s2;
- cin >> a >> b;
- 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); }
- 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); }
- 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); }
- 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); }
- cout << s1-s2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement