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