Skip to content

Instantly share code, notes, and snippets.

@yurahuna
Created September 22, 2016 05:39
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 yurahuna/962fd2d9ea8f5c8332a69721afa3d2dc to your computer and use it in GitHub Desktop.
Save yurahuna/962fd2d9ea8f5c8332a69721afa3d2dc to your computer and use it in GitHub Desktop.
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n, d;
cin >> n >> d;
int ans;
if (d == 1) {
ans = n * (n - 1) / 2;
} else {
ans = (n - 1) + (n - d - 1) * n - (n - d - 1) * (n + d - 2) / 2;
}
cout << ans << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment