Skip to content

Instantly share code, notes, and snippets.

@completejavascript
Created October 9, 2018 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save completejavascript/0b05c37ae33f445f80f0e613050c4c8a to your computer and use it in GitHub Desktop.
Save completejavascript/0b05c37ae33f445f80f0e613050c4c8a to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
long long sumAll(long long a, long long b) {
long long n;
if (b > a) n = b - a + 1;
else n = a - b + 1;
return n * (a + b) / 2;
}
int main() {
ios::sync_with_stdio(false);
//freopen("input.txt", "r", stdin);
int a, b;
while(cin >> a >> b) {
cout << sumAll(a, b) << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment